node_modules: update (#344)

Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
This commit is contained in:
Dawid Dziurlaanddawidd6 authored and GitHub committed 2026-10-10 17:27:57 +02:00
1 parent b099186883
commit 6e88c72525
63 files changed
+2863 -1227

No files matched your search

+3
View File
@@ -24,6 +24,9 @@ export interface EncoderOptions {
/**
* Creates a transform stream for encoding data to base64 encoding
*
* The output is the same as `wrap(encode(input), lineLength)` no matter how the input is split
* into chunks: every line but the last one ends with a line break, the last one does not
*
* @constructor
* @param options Stream options
* @param [options.lineLength=76] Maximum length for lines, set to false to disable wrapping
+80 -41
View File
@@ -16,6 +16,47 @@ function encode(buffer) {
}
return buffer.toString('base64');
}
/**
* Turns a line length option into a whole number of characters, the default for anything unusable
*/
function normalizeLineLength(lineLength) {
const length = Math.floor(Number(lineLength));
return Number.isFinite(length) && length >= 1 ? length : 76;
}
/**
* Splits the bytes of `src` into lines of `lineLength` bytes, each followed by a line break. With
* `final` set the last line, which may be shorter, gets no line break; otherwise only complete
* lines are taken and the rest is left for the caller
*
* @param src Bytes to wrap
* @param lineLength Line length
* @param final Whether `src` ends the output
* @returns The wrapped bytes and the number of trailing bytes not taken
*/
function wrapBuffer(src, lineLength, final) {
const lines = Math.ceil(src.length / lineLength);
// the last line waits for more data unless this is the end: whether it gets a line break
// depends on whether anything follows it
const complete = Math.max(lines - 1, 0);
let rest = src.length - complete * lineLength;
const output = Buffer.allocUnsafe(complete * (lineLength + 2) + (final ? rest : 0));
let to = 0;
for (let from = 0; from < complete * lineLength; from += lineLength) {
src.copy(output, to, from, from + lineLength);
to += lineLength;
output[to++] = 0x0d;
output[to++] = 0x0a;
}
if (final) {
to += src.copy(output, to, complete * lineLength);
rest = 0;
}
if (to !== output.length) {
// never hand out bytes of the unfilled allocation
throw new Error('Unexpected wrapped length');
}
return { output, rest };
}
/**
* Adds soft line breaks to a base64 string
*
@@ -44,6 +85,9 @@ function wrap(str, lineLength) {
/**
* Creates a transform stream for encoding data to base64 encoding
*
* The output is the same as `wrap(encode(input), lineLength)` no matter how the input is split
* into chunks: every line but the last one ends with a line break, the last one does not
*
* @constructor
* @param options Stream options
* @param [options.lineLength=76] Maximum length for lines, set to false to disable wrapping
@@ -53,66 +97,61 @@ class Encoder extends node_stream_1.Transform {
super();
this.options = options || {};
if (this.options.lineLength !== false) {
this.options.lineLength = this.options.lineLength || 76;
this.options.lineLength = normalizeLineLength(this.options.lineLength);
}
this._curLine = '';
this._remainingBytes = false;
this.inputBytes = 0;
this.outputBytes = 0;
}
/**
* Emits the encoded characters `b64` that follow the current line, keeping what can not be
* emitted yet as the new current line
*
* @internal
*/
_emit(b64, final) {
const src = Buffer.from(this._curLine + b64, 'latin1');
if (!src.length) {
return;
}
let output = src;
if (this.options.lineLength) {
const wrapped = wrapBuffer(src, this.options.lineLength, final);
output = wrapped.output;
this._curLine = wrapped.rest ? src.toString('latin1', src.length - wrapped.rest) : '';
}
else {
this._curLine = '';
}
if (output.length) {
this.outputBytes += output.length;
this.push(output);
}
}
/** @internal */
_transform(chunk, encoding, done) {
let buf = encoding !== 'buffer' ? Buffer.from(chunk, encoding) : chunk;
if (!buf || !buf.length) {
setImmediate(done);
return;
return done();
}
this.inputBytes += buf.length;
if (this._remainingBytes && this._remainingBytes.length) {
if (this._remainingBytes) {
buf = Buffer.concat([this._remainingBytes, buf], this._remainingBytes.length + buf.length);
this._remainingBytes = false;
}
if (buf.length % 3) {
this._remainingBytes = buf.slice(buf.length - (buf.length % 3));
buf = buf.slice(0, buf.length - (buf.length % 3));
const extra = buf.length % 3;
if (extra) {
this._remainingBytes = buf.subarray(buf.length - extra);
buf = buf.subarray(0, buf.length - extra);
}
else {
this._remainingBytes = false;
}
let b64 = this._curLine + encode(buf);
if (this.options.lineLength) {
b64 = wrap(b64, this.options.lineLength);
// remove last line as it is still most probably incomplete
const lastLF = b64.lastIndexOf('\n');
if (lastLF < 0) {
this._curLine = b64;
b64 = '';
}
else if (lastLF === b64.length - 1) {
this._curLine = '';
}
else {
this._curLine = b64.substring(lastLF + 1);
b64 = b64.substring(0, lastLF + 1);
}
}
if (b64) {
this.outputBytes += b64.length;
this.push(Buffer.from(b64, 'ascii'));
}
setImmediate(done);
this._emit(encode(buf), false);
done();
}
/** @internal */
_flush(done) {
if (this._remainingBytes && this._remainingBytes.length) {
this._curLine += encode(this._remainingBytes);
}
if (this._curLine) {
this._curLine = wrap(this._curLine, this.options.lineLength);
this.outputBytes += this._curLine.length;
this.push(Buffer.from(this._curLine, 'ascii'));
this._curLine = '';
}
this._emit(this._remainingBytes ? encode(this._remainingBytes) : '', true);
this._remainingBytes = false;
done();
}
}