THE_DEVELOPER_GUIDE Telegram 5743
ุฏุฑุฏุดุฉ ุณุฑูŠุนุฉ ุนู† ุงู„ู€ Buffer ููŠ Node.js ๐Ÿ’ฏ
.
.
ุฃุบู„ุจ ุงู„ูˆู‚ุช ูˆุฅุญู†ุง ุจู†ูƒุชุจ ูƒูˆุฏ ููŠ Node.jsุŒ ุจู†ุชุนุงู…ู„ ู…ุน ุงู„ุจูŠุงู†ุงุช ุงู„ู„ูŠ ุฑุงุฌุนู‡ ู…ู† ุงู„ู€ APIs ุฃูˆ ู…ู† ุงู„ู€ Database ุฃูˆ ู…ู† ุงู„ู€ Files ุนู„ู‰ ู‡ูŠุฆุฉ Strings ุฃูˆ JSON. ุชู…ุงู… ูƒุฏู‡ุŸ ู„ูƒู†ุŒ ู„ูˆ ู‡ู†ุชุนุงู…ู„ ู…ุน ุญุงุฌุงุช ุฒูŠ ุงู„ุตูˆุฑุŒ ุงู„ู…ู„ูุงุช ุงู„ุตูˆุชูŠุฉุŒ ุงู„ููŠุฏูŠูˆุŒ ุฃูˆ ุฃูŠ Data ุบูŠุฑ ู†ุตูŠู‘ุฉ (non-text)ุŒ ูˆู‚ุชู‡ุง ุงู„ู€ JavaScript ู…ุง ุชุนุฑู ุชุชุนุงู…ู„ ู…ุน ุงู„ู†ูˆุน ุฏู‡ ุจุดูƒู„ ู…ุจุงุดุฑ. ูˆู‡ู†ุง ูŠูŠุฌูŠ ุฏูˆุฑ ุงู„ู€ Buffer.

โ€”โ€”โ€”

๐Ÿ“Œ ุฅูŠู‡ ู‡ูˆ ุงู„ู€ BufferุŸ

ุงู„ู€ Buffer ู‡ูˆ ุจุจุณุงุทุฉ ุทุฑูŠู‚ุฉ Node.js ู„ู„ุชุนุงู…ู„ ู…ุน ุงู„ุจูŠุงู†ุงุช ุงู„ุฎุงู… (Raw Binary Data) ุงู„ู„ูŠ ุฑุงุฌุนุฉ ู…ู† ุฃูˆ ุฑุงูŠุญุฉ ู„ู…ุตุฏุฑ ุฎุงุฑุฌูŠุŒ ุฒูŠ ู…ุซู„ู‹ุง File System ุฃูˆ TCP StreamุŒ ุฃูˆ ุญุชู‰ ู…ู† HTTP Response.

ูŠุนู†ูŠ ู„ูˆ ุนู†ุฏูƒ ูุงูŠู„ MP3ุŒ ุฃู†ุช ู…ุด ู‡ุชู‚ุฑุฃู‡ ูƒู€ "ู†ุต"ุŒ ุฃู†ุช ู‡ุชู‚ุฑุฃู‡ ูƒู€ ุณู„ุณู„ุฉ ู…ู† ุงู„ุฃุฑู‚ุงู… (bytes). ูˆุงู„ู€ Buffer ุจูŠุณู…ุญู„ูƒ ุชู…ุณูƒ ุงู„ุณู„ุณู„ุฉ ุฏูŠุŒ ูˆุชุชุนุงู…ู„ ู…ุนุงู‡ุง ููŠ ุงู„ุฐุงูƒุฑุฉ.

โ€”โ€”โ€”

๐Ÿ“ฆ ู„ูŠู‡ Node.js ุจุชุณุชุฎุฏู… BuffersุŸ

ุนู„ุดุงู† Node.js ู…ุจู†ูŠุฉ ุญูˆู„ ุงู„ู€ Streams. ูˆุงู„ู€ Streams ููŠ ุงู„ุบุงู„ุจ ู…ุด ุจุชุฏูŠู„ูƒ ุงู„ุจูŠุงู†ุงุช ูƒู„ู‡ุง ู…ุฑุฉ ูˆุงุญุฏุฉุŒ ุจุชุจุนุชู‡ุง ู„ูƒ ุฌุฒุก ุฌุฒุก.

ู…ุซุงู„ ุจุณูŠุท:
ู„ูˆ ุจุชู‚ุฑุฃ ูุงูŠู„ ูƒุจูŠุฑ ู…ู† ุนู„ู‰ ุงู„ู‡ุงุฑุฏุŒ ุงู„ู€ Node.js ู…ุด ู‡ุชุญู…ู‘ู„ ุงู„ูุงูŠู„ ูƒู„ู‡ ููŠ RAM ู…ุฑุฉ ูˆุงุญุฏุฉ (ุนุดุงู† ุฏู‡ ู…ุด ุนู…ู„ูŠ ูˆู…ู…ูƒู† ูŠู…ูˆุช ุงู„ุณูŠุณุชู… ู„ูˆ ุงู„ูุงูŠู„ ูƒุจูŠุฑ ุฌุฏู‹ุง)ุŒ ู‡ูŠ ุจุชู‚ุฑุฃ Chunk ุจู€ Chunk. ูƒู„ Chunk ู…ู† ุฏูˆู„ ู‡ูˆ ุนุจุงุฑุฉ ุนู† Buffer.

โ€”โ€”โ€”

๐Ÿ’ก ู…ุซุงู„ ุนู…ู„ูŠ

const fs = require('fs');

const readableStream = fs.createReadStream('video.mp4');

readableStream.on('data', (chunk) => {
  console.log('Received chunk:', chunk);
  console.log('Chunk is a buffer?',   

  Buffer.isBuffer(chunk)); // true
});

ููŠ ุงู„ู…ุซุงู„ ุฏู‡ุŒ ูƒู„ ู…ุฑุฉ ุงู„ู€ Stream ุจูŠุจุนุช DataุŒ ุจู†ุณุชู‚ุจู„ู‡ุง ุนู„ู‰ ู‡ูŠุฆุฉ Buffer. ุชู‚ุฏุฑ ุชุชุนุงู…ู„ ู…ุนุงู‡ุงุŒ ุชุฎุฒู†ู‡ุงุŒ ุชุจุนุชู‡ุงุŒ ุฃูˆ ุญุชู‰ ุชุนุฏู‘ู„ ููŠู‡ุง.

โ€”โ€”โ€”

โœจ ุดูˆูŠุฉ ุญุงุฌุงุช ู…ู‡ู…ุฉ ุนู† Buffer:

- ุงู„ู€ Buffer.from: ุจูŠุญูˆู‘ู„ ุฃูŠ String ุฃูˆ Array ุฃูˆ ุญุชู‰ ArrayBuffer ู„ู€ Buffer.
- ุงู„ู€ Buffer.alloc(size): ุจูŠุนู…ู„ Buffer ูุงุถูŠ ุจุงู„ุญุฌู… ุงู„ู„ูŠ ุชุญุฏุฏู‡.
- ุงู„ู€ buffer.toString: ู„ูˆ ุนุงูŠุฒ ุชุฑุฌู‘ุน ุงู„ู€ Buffer ู„ุตูŠุบุฉ String (ู„ูˆ ุฃุตู„ู‹ุง ูƒุงู†ุช Text).

โ€”โ€”โ€”

ู„ุงุฒู… ุชูƒูˆู† ูุงู‡ู… ูŠุนู†ูŠ ุฅูŠู‡ Buffer ููŠ ุงู„ุญุงู„ุงุช ุฏูŠ:

- ู„ูˆ ุจุชุชุนุงู…ู„ ู…ุน ุงู„ู…ู„ูุงุช ุงู„ูƒุจูŠุฑุฉ.
- ู„ูˆ ุดุบุงู„ ุนู„ู‰ ุชุทุจูŠู‚ ุจูŠุณุชู‚ุจู„ ุตูˆุฑ ุฃูˆ ููŠุฏูŠูˆู‡ุงุช ุฃูˆ ุฃุตูˆุงุช.
- ู„ูˆ ุดุบุงู„ ู…ุน Streams (ุฒูŠ HTTP Requests ุฃูˆ TCP Connections).
- ู„ูˆ ุจุชุจุนุช ุฃูˆ ุจุชุณุชู‚ุจู„ Binary Data ู…ู† API ุฃูˆ ุฌู‡ุงุฒ ุชุงู†ูŠ.

โ€”โ€”โ€”

ุงู„ู€ Buffers ุจุชุดุชุบู„ ุนู„ู‰ ู…ุณุชูˆู‰ ุงู„ู€ Memory ู…ุจุงุดุฑุฉุŒ ูŠุนู†ูŠ ู„ูˆ ู…ุนุฑูุชุด ุชุชุนุงู…ู„ ู…ุนุงู‡ู… ุตุญุŒ ู…ู…ูƒู† ุชู‚ุน ููŠ ู…ุดุงูƒู„ ุฒูŠ memory leaks ุฃูˆ inefficient data handling.

โ€”โ€”โ€”

ูˆูู‚ูƒู… ุงู„ู„ู‡ ู„ูƒู„ ุฎูŠุฑ ๐ŸŒฟ
โค5



tgoop.com/the_developer_guide/5743
Create:
Last Update:

ุฏุฑุฏุดุฉ ุณุฑูŠุนุฉ ุนู† ุงู„ู€ Buffer ููŠ Node.js ๐Ÿ’ฏ
.
.
ุฃุบู„ุจ ุงู„ูˆู‚ุช ูˆุฅุญู†ุง ุจู†ูƒุชุจ ูƒูˆุฏ ููŠ Node.jsุŒ ุจู†ุชุนุงู…ู„ ู…ุน ุงู„ุจูŠุงู†ุงุช ุงู„ู„ูŠ ุฑุงุฌุนู‡ ู…ู† ุงู„ู€ APIs ุฃูˆ ู…ู† ุงู„ู€ Database ุฃูˆ ู…ู† ุงู„ู€ Files ุนู„ู‰ ู‡ูŠุฆุฉ Strings ุฃูˆ JSON. ุชู…ุงู… ูƒุฏู‡ุŸ ู„ูƒู†ุŒ ู„ูˆ ู‡ู†ุชุนุงู…ู„ ู…ุน ุญุงุฌุงุช ุฒูŠ ุงู„ุตูˆุฑุŒ ุงู„ู…ู„ูุงุช ุงู„ุตูˆุชูŠุฉุŒ ุงู„ููŠุฏูŠูˆุŒ ุฃูˆ ุฃูŠ Data ุบูŠุฑ ู†ุตูŠู‘ุฉ (non-text)ุŒ ูˆู‚ุชู‡ุง ุงู„ู€ JavaScript ู…ุง ุชุนุฑู ุชุชุนุงู…ู„ ู…ุน ุงู„ู†ูˆุน ุฏู‡ ุจุดูƒู„ ู…ุจุงุดุฑ. ูˆู‡ู†ุง ูŠูŠุฌูŠ ุฏูˆุฑ ุงู„ู€ Buffer.

โ€”โ€”โ€”

๐Ÿ“Œ ุฅูŠู‡ ู‡ูˆ ุงู„ู€ BufferุŸ

ุงู„ู€ Buffer ู‡ูˆ ุจุจุณุงุทุฉ ุทุฑูŠู‚ุฉ Node.js ู„ู„ุชุนุงู…ู„ ู…ุน ุงู„ุจูŠุงู†ุงุช ุงู„ุฎุงู… (Raw Binary Data) ุงู„ู„ูŠ ุฑุงุฌุนุฉ ู…ู† ุฃูˆ ุฑุงูŠุญุฉ ู„ู…ุตุฏุฑ ุฎุงุฑุฌูŠุŒ ุฒูŠ ู…ุซู„ู‹ุง File System ุฃูˆ TCP StreamุŒ ุฃูˆ ุญุชู‰ ู…ู† HTTP Response.

ูŠุนู†ูŠ ู„ูˆ ุนู†ุฏูƒ ูุงูŠู„ MP3ุŒ ุฃู†ุช ู…ุด ู‡ุชู‚ุฑุฃู‡ ูƒู€ "ู†ุต"ุŒ ุฃู†ุช ู‡ุชู‚ุฑุฃู‡ ูƒู€ ุณู„ุณู„ุฉ ู…ู† ุงู„ุฃุฑู‚ุงู… (bytes). ูˆุงู„ู€ Buffer ุจูŠุณู…ุญู„ูƒ ุชู…ุณูƒ ุงู„ุณู„ุณู„ุฉ ุฏูŠุŒ ูˆุชุชุนุงู…ู„ ู…ุนุงู‡ุง ููŠ ุงู„ุฐุงูƒุฑุฉ.

โ€”โ€”โ€”

๐Ÿ“ฆ ู„ูŠู‡ Node.js ุจุชุณุชุฎุฏู… BuffersุŸ

ุนู„ุดุงู† Node.js ู…ุจู†ูŠุฉ ุญูˆู„ ุงู„ู€ Streams. ูˆุงู„ู€ Streams ููŠ ุงู„ุบุงู„ุจ ู…ุด ุจุชุฏูŠู„ูƒ ุงู„ุจูŠุงู†ุงุช ูƒู„ู‡ุง ู…ุฑุฉ ูˆุงุญุฏุฉุŒ ุจุชุจุนุชู‡ุง ู„ูƒ ุฌุฒุก ุฌุฒุก.

ู…ุซุงู„ ุจุณูŠุท:
ู„ูˆ ุจุชู‚ุฑุฃ ูุงูŠู„ ูƒุจูŠุฑ ู…ู† ุนู„ู‰ ุงู„ู‡ุงุฑุฏุŒ ุงู„ู€ Node.js ู…ุด ู‡ุชุญู…ู‘ู„ ุงู„ูุงูŠู„ ูƒู„ู‡ ููŠ RAM ู…ุฑุฉ ูˆุงุญุฏุฉ (ุนุดุงู† ุฏู‡ ู…ุด ุนู…ู„ูŠ ูˆู…ู…ูƒู† ูŠู…ูˆุช ุงู„ุณูŠุณุชู… ู„ูˆ ุงู„ูุงูŠู„ ูƒุจูŠุฑ ุฌุฏู‹ุง)ุŒ ู‡ูŠ ุจุชู‚ุฑุฃ Chunk ุจู€ Chunk. ูƒู„ Chunk ู…ู† ุฏูˆู„ ู‡ูˆ ุนุจุงุฑุฉ ุนู† Buffer.

โ€”โ€”โ€”

๐Ÿ’ก ู…ุซุงู„ ุนู…ู„ูŠ

const fs = require('fs');

const readableStream = fs.createReadStream('video.mp4');

readableStream.on('data', (chunk) => {
  console.log('Received chunk:', chunk);
  console.log('Chunk is a buffer?',   

  Buffer.isBuffer(chunk)); // true
});

ููŠ ุงู„ู…ุซุงู„ ุฏู‡ุŒ ูƒู„ ู…ุฑุฉ ุงู„ู€ Stream ุจูŠุจุนุช DataุŒ ุจู†ุณุชู‚ุจู„ู‡ุง ุนู„ู‰ ู‡ูŠุฆุฉ Buffer. ุชู‚ุฏุฑ ุชุชุนุงู…ู„ ู…ุนุงู‡ุงุŒ ุชุฎุฒู†ู‡ุงุŒ ุชุจุนุชู‡ุงุŒ ุฃูˆ ุญุชู‰ ุชุนุฏู‘ู„ ููŠู‡ุง.

โ€”โ€”โ€”

โœจ ุดูˆูŠุฉ ุญุงุฌุงุช ู…ู‡ู…ุฉ ุนู† Buffer:

- ุงู„ู€ Buffer.from: ุจูŠุญูˆู‘ู„ ุฃูŠ String ุฃูˆ Array ุฃูˆ ุญุชู‰ ArrayBuffer ู„ู€ Buffer.
- ุงู„ู€ Buffer.alloc(size): ุจูŠุนู…ู„ Buffer ูุงุถูŠ ุจุงู„ุญุฌู… ุงู„ู„ูŠ ุชุญุฏุฏู‡.
- ุงู„ู€ buffer.toString: ู„ูˆ ุนุงูŠุฒ ุชุฑุฌู‘ุน ุงู„ู€ Buffer ู„ุตูŠุบุฉ String (ู„ูˆ ุฃุตู„ู‹ุง ูƒุงู†ุช Text).

โ€”โ€”โ€”

ู„ุงุฒู… ุชูƒูˆู† ูุงู‡ู… ูŠุนู†ูŠ ุฅูŠู‡ Buffer ููŠ ุงู„ุญุงู„ุงุช ุฏูŠ:

- ู„ูˆ ุจุชุชุนุงู…ู„ ู…ุน ุงู„ู…ู„ูุงุช ุงู„ูƒุจูŠุฑุฉ.
- ู„ูˆ ุดุบุงู„ ุนู„ู‰ ุชุทุจูŠู‚ ุจูŠุณุชู‚ุจู„ ุตูˆุฑ ุฃูˆ ููŠุฏูŠูˆู‡ุงุช ุฃูˆ ุฃุตูˆุงุช.
- ู„ูˆ ุดุบุงู„ ู…ุน Streams (ุฒูŠ HTTP Requests ุฃูˆ TCP Connections).
- ู„ูˆ ุจุชุจุนุช ุฃูˆ ุจุชุณุชู‚ุจู„ Binary Data ู…ู† API ุฃูˆ ุฌู‡ุงุฒ ุชุงู†ูŠ.

โ€”โ€”โ€”

ุงู„ู€ Buffers ุจุชุดุชุบู„ ุนู„ู‰ ู…ุณุชูˆู‰ ุงู„ู€ Memory ู…ุจุงุดุฑุฉุŒ ูŠุนู†ูŠ ู„ูˆ ู…ุนุฑูุชุด ุชุชุนุงู…ู„ ู…ุนุงู‡ู… ุตุญุŒ ู…ู…ูƒู† ุชู‚ุน ููŠ ู…ุดุงูƒู„ ุฒูŠ memory leaks ุฃูˆ inefficient data handling.

โ€”โ€”โ€”

ูˆูู‚ูƒู… ุงู„ู„ู‡ ู„ูƒู„ ุฎูŠุฑ ๐ŸŒฟ

BY DevGuide ๐Ÿ‡ต๐Ÿ‡ธ


Share with your friend now:
tgoop.com/the_developer_guide/5743

View MORE
Open in Telegram


Telegram News

Date: |

As five out of seven counts were serious, Hui sentenced Ng to six years and six months in jail. Add the logo from your device. Adjust the visible area of your image. Congratulations! Now your Telegram channel has a face Click โ€œSaveโ€.! The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously. Users are more open to new information on workdays rather than weekends. The channel also called on people to turn out for illegal assemblies and listed the things that participants should bring along with them, showing prior planning was in the works for riots. The messages also incited people to hurl toxic gas bombs at police and MTR stations, he added.
from us


Telegram DevGuide ๐Ÿ‡ต๐Ÿ‡ธ
FROM American