Server IP : 185.86.78.101 / Your IP : 216.73.216.124 Web Server : Apache System : Linux 675867-vds-valikoshka1996.gmhost.pp.ua 5.4.0-150-generic #167-Ubuntu SMP Mon May 15 17:35:05 UTC 2023 x86_64 User : www ( 1000) PHP Version : 7.4.33 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/wwwroot/mifepriston.org/node_modules/first-chunk-stream/ |
Upload File : |
# first-chunk-stream [](https://travis-ci.org/sindresorhus/first-chunk-stream) > Buffer and transform the n first bytes of a stream ## Install ``` $ npm install --save first-chunk-stream ``` ## Usage ```js const fs = require('fs'); const concatStream = require('concat-stream'); const firstChunkStream = require('first-chunk-stream'); // unicorn.txt => unicorn rainbow fs.createReadStream('unicorn.txt') .pipe(firstChunkStream({chunkLength: 7}, function (chunk, enc, cb) { this.push(chunk.toUpperCase()); cb(); })) .pipe(concatStream(function (data) { if (data.length < 7) { throw new Error('Couldn\'t get the minimum required first chunk length'); } console.log(data); //=> 'UNICORN rainbow' })); ``` ## API ### firstChunkStream([options], transform) Returns a `FirstChunkStream` instance. #### options The options object is passed to the [`Duplex` stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex) constructor allowing you to customize your stream behavior. In addition you can specify the following option: ##### chunkLength Type: `number` How many bytes you want to buffer. #### transform(chunk, encoding, callback) Type: `function` The function that gets the required `options.chunkLength` bytes. Note that the buffer can have a smaller length than the required one. In that case, it will be due to the fact that the complete stream contents has a length less than the `òptions.chunkLength` value. You should check for this yourself if you strictly depend on the length. ## License MIT © [Sindre Sorhus](http://sindresorhus.com)