{"_id":"@cjser/first-chunk-stream__v5_0_0","name":"@cjser/first-chunk-stream__v5_0_0","dist-tags":{"latest":"5.0.0-cjser.2"},"versions":{"5.0.0-cjser.2":{"name":"@cjser/first-chunk-stream__v5_0_0","version":"5.0.0-cjser.2","description":"Buffer and transform the n first bytes of a stream","license":"MIT","repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"funding":"https://github.com/sponsors/sindresorhus","author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"type":"module","exports":{"require":"./dist-cjser/index.cjs","default":"./index.js"},"engines":{"node":"^12.20.0 || ^14.13.1 || >=16.0.0"},"scripts":{"test":"xo && nyc ava && tsd"},"keywords":["buffer","stream","streams","transform","first","chunk","size","minimum","bytes"],"devDependencies":{"@types/node":"^16.6.1","ava":"^3.15.0","nyc":"^15.1.0","streamtest":"^2.0.0","tsd":"^0.17.0","xo":"^0.44.0"},"main":"./dist-cjser/index.cjs","cjser":{"sourceVersion":"5.0.0","cjserVersion":2,"original":{"name":"first-chunk-stream","version":"5.0.0","exports":"./index.js","repository":"sindresorhus/first-chunk-stream","files":["index.js","index.d.ts"],"scripts":{"test":"xo && nyc ava && tsd"}}},"_id":"@cjser/first-chunk-stream__v5_0_0@5.0.0-cjser.2","gitHead":"a4bef54d7d22d3d9a6b84528457938d84cd65fe7","_nodeVersion":"20.14.0","_npmVersion":"10.7.0","dist":{"integrity":"sha512-ywJ0bY219kjTkcPchTqroeOUEgMU6gllB3Ry72eljjlKRwKSO8krpbw+KnytgIAMwusMwkM2N7a9XnKtIZQOsQ==","shasum":"8de6c47c4113f79d7ce97517c6893f2d83de4273","tarball":"https://registry.npmjs.org/@cjser/first-chunk-stream__v5_0_0/-/first-chunk-stream__v5_0_0-5.0.0-cjser.2.tgz","fileCount":6,"unpackedSize":16282,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIBPncA/idlpzLaMi7SD8IApf6QlW06IgpQCPQQlI3bsEAiEAzKUpHj4qB9FuLjtV59zu8WexpDHjmOJbkETAbeQpmtY="}]},"_npmUser":{"name":"nanahira","email":"nanahira@momobako.com"},"directories":{},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/first-chunk-stream__v5_0_0_5.0.0-cjser.2_1778158158274_0.78393611577163"},"_hasShrinkwrap":false}},"time":{"created":"2026-05-07T12:49:18.182Z","5.0.0-cjser.2":"2026-05-07T12:49:18.402Z","modified":"2026-05-07T12:49:18.561Z"},"maintainers":[{"name":"nanahira","email":"nanahira@momobako.com"}],"description":"Buffer and transform the n first bytes of a stream","keywords":["buffer","stream","streams","transform","first","chunk","size","minimum","bytes"],"repository":{"type":"git","url":"https://code.moenext.com/3rdeye/cjser.git"},"author":{"name":"Sindre Sorhus","email":"sindresorhus@gmail.com","url":"https://sindresorhus.com"},"license":"MIT","readme":"# first-chunk-stream\n\n> Buffer and transform the n first bytes of a stream\n\n## Install\n\n```\n$ npm install first-chunk-stream\n```\n\n## Usage\n\n```js\nimport fs from 'node:fs';\nimport getStream from 'get-stream';\nimport FirstChunkStream from 'first-chunk-stream';\n\n// unicorn.txt => unicorn rainbow\nconst stream = fs.createReadStream('unicorn.txt')\n\t.pipe(new FirstChunkStream({chunkSize: 7}, async (chunk, encoding) => {\n\t\treturn chunk.toString(encoding).toUpperCase();\n\t}));\n\nconst data = await getStream(stream);\n\nif (data.length < 7) {\n\tthrow new Error('Couldn\\'t get the minimum required first chunk length');\n}\n\nconsole.log(data);\n//=> 'UNICORN rainbow'\n```\n\n## API\n\n### FirstChunkStream(options, transform)\n\n`FirstChunkStream` constructor.\n\n#### transform(chunk, encoding)\n\nType: `Function`\n\nAsync function that receives the required `options.chunkSize` bytes.\n\nExpected to return an buffer-like object or `string` or object of form {buffer: `Buffer`, encoding: `string`} to send to stream or `firstChunkStream.stop` to end stream right away.\n\nAn error thrown from this function will be emitted as stream errors.\n\nNote 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 `options.chunkSize` value. You should check for this yourself if you strictly depend on the length.\n\n```js\nimport FirstChunkStream from 'first-chunk-stream';\n\nnew FirstChunkStream({chunkSize: 7}, async (chunk, encoding) => {\n\treturn chunk.toString(encoding).toUpperCase(); // Send string to stream\n});\n\nnew FirstChunkStream({chunkSize: 7}, async (chunk, encoding) => {\n\treturn chunk; // Send buffer to stream\n});\n\nnew FirstChunkStream({chunkSize: 7}, async (chunk, encoding) => {\n\treturn {\n\t\tbuffer: chunk,\n\t\tencoding: encoding,\n\t}; // Send buffer with encoding to stream\n});\n\nnew FirstChunkStream({chunkSize: 7}, async (chunk, encoding) => {\n\treturn FirstChunkStream.stop; // End the stream early\n});\n\nnew FirstChunkStream({chunkSize: 7}, async (chunk, encoding) => {\n\tthrow new Error('Unconditional error'); // Emit stream error\n});\n```\n\n#### options\n\nType: `object`\n\nThe 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:\n\n###### chunkSize\n\nType: `number`\n\nThe number of bytes to buffer.\n\n## cjser\n\nThis package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.\nOriginal repository: https://github.com/sindresorhus/first-chunk-stream\n","readmeFilename":"readme.md","_rev":"1-d013b3f848666e8cf022de2c62b5c4f5"}