Download .opencode/node_modules/msgpackr/stream.js from Chenloong999/opencode-data: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/datasets/Chenloong999/opencode-data/resolve/84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/msgpackr/stream.js
- Command line
-
hf download hf://datasets/Chenloong999/opencode-data@84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/msgpackr/stream.js
-
curl -L -o stream.js https://huggingface.co/datasets/Chenloong999/opencode-data/resolve/84c8581d284a6a73a22921151ea3d89e2bcfe44e/.opencode/node_modules/msgpackr/stream.js
1.66 kB
| import { Transform } from 'stream' | |
| import { Packr } from './pack.js' | |
| import { Unpackr } from './unpack.js' | |
| var DEFAULT_OPTIONS = {objectMode: true} | |
| export class PackrStream extends Transform { | |
| constructor(options) { | |
| if (!options) | |
| options = {} | |
| options.writableObjectMode = true | |
| super(options) | |
| options.sequential = true | |
| this.packr = options.packr || new Packr(options) | |
| } | |
| _transform(value, encoding, callback) { | |
| this.push(this.packr.pack(value)) | |
| callback() | |
| } | |
| } | |
| export class UnpackrStream extends Transform { | |
| constructor(options) { | |
| if (!options) | |
| options = {} | |
| options.objectMode = true | |
| super(options) | |
| options.structures = [] | |
| this.maxIncompleteBufferSize = options.maxIncompleteBufferSize !== undefined ? options.maxIncompleteBufferSize : 0x4000000 | |
| this.unpackr = options.unpackr || new Unpackr(options) | |
| } | |
| _transform(chunk, encoding, callback) { | |
| if (this.incompleteBuffer) { | |
| chunk = Buffer.concat([this.incompleteBuffer, chunk]) | |
| this.incompleteBuffer = null | |
| } | |
| let values | |
| try { | |
| values = this.unpackr.unpackMultiple(chunk) | |
| } catch(error) { | |
| if (error.incomplete) { | |
| let incompleteBuffer = chunk.slice(error.lastPosition) | |
| if (incompleteBuffer.length > this.maxIncompleteBufferSize) { | |
| this.incompleteBuffer = null | |
| return callback(new Error('Maximum incomplete buffer size exceeded')) | |
| } | |
| this.incompleteBuffer = incompleteBuffer | |
| values = error.values | |
| } else { | |
| return callback(error) | |
| } | |
| } | |
| for (let value of values || []) { | |
| if (value === null) | |
| value = this.getNullValue() | |
| this.push(value) | |
| } | |
| callback() | |
| } | |
| getNullValue() { | |
| return Symbol.for(null) | |
| } | |
| } | |