Initial commit, 90% there

This commit is contained in:
mdares
2025-12-02 16:27:21 +00:00
commit 755028af7e
7353 changed files with 1759505 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
/// <reference types="node" />
/// <reference types="node" />
import { Transform, TransformCallback, TransformOptions } from 'stream';
export interface ByteLengthOptions extends TransformOptions {
/** the number of bytes on each data event */
length: number;
}
/**
* Emit data every number of bytes
*
* A transform stream that emits data as a buffer after a specific number of bytes are received. Runs in O(n) time.
*/
export declare class ByteLengthParser extends Transform {
length: number;
private position;
private buffer;
constructor(options: ByteLengthOptions);
_transform(chunk: Buffer, _encoding: BufferEncoding, cb: TransformCallback): void;
_flush(cb: TransformCallback): void;
}

View File

@@ -0,0 +1,46 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ByteLengthParser = void 0;
const stream_1 = require("stream");
/**
* Emit data every number of bytes
*
* A transform stream that emits data as a buffer after a specific number of bytes are received. Runs in O(n) time.
*/
class ByteLengthParser extends stream_1.Transform {
length;
position;
buffer;
constructor(options) {
super(options);
if (typeof options.length !== 'number') {
throw new TypeError('"length" is not a number');
}
if (options.length < 1) {
throw new TypeError('"length" is not greater than 0');
}
this.length = options.length;
this.position = 0;
this.buffer = Buffer.alloc(this.length);
}
_transform(chunk, _encoding, cb) {
let cursor = 0;
while (cursor < chunk.length) {
this.buffer[this.position] = chunk[cursor];
cursor++;
this.position++;
if (this.position === this.length) {
this.push(this.buffer);
this.buffer = Buffer.alloc(this.length);
this.position = 0;
}
}
cb();
}
_flush(cb) {
this.push(this.buffer.slice(0, this.position));
this.buffer = Buffer.alloc(this.length);
cb();
}
}
exports.ByteLengthParser = ByteLengthParser;