2026-09-15 13:00:32 +02:00
|
|
|
"use strict";
|
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
|
const node_stream_1 = require("node:stream");
|
2020-02-29 23:01:03 +01:00
|
|
|
/**
|
|
|
|
|
* Ensures that only <CR><LF> sequences are used for linebreaks
|
|
|
|
|
*
|
2026-09-15 13:00:32 +02:00
|
|
|
* @param options Stream options
|
2020-02-29 23:01:03 +01:00
|
|
|
*/
|
2026-09-15 13:00:32 +02:00
|
|
|
class LeWindows extends node_stream_1.Transform {
|
2020-02-29 23:01:03 +01:00
|
|
|
constructor(options) {
|
|
|
|
|
super(options);
|
|
|
|
|
this.lastByte = false;
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* Escapes dots
|
2026-09-15 13:00:32 +02:00
|
|
|
* @internal
|
2020-02-29 23:01:03 +01:00
|
|
|
*/
|
|
|
|
|
_transform(chunk, encoding, done) {
|
|
|
|
|
let buf;
|
|
|
|
|
let lastPos = 0;
|
|
|
|
|
for (let i = 0, len = chunk.length; i < len; i++) {
|
|
|
|
|
if (chunk[i] === 0x0a) {
|
|
|
|
|
// \n
|
|
|
|
|
if ((i && chunk[i - 1] !== 0x0d) || (!i && this.lastByte !== 0x0d)) {
|
|
|
|
|
if (i > lastPos) {
|
|
|
|
|
buf = chunk.slice(lastPos, i);
|
|
|
|
|
this.push(buf);
|
|
|
|
|
}
|
|
|
|
|
this.push(Buffer.from('\r\n'));
|
|
|
|
|
lastPos = i + 1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (lastPos && lastPos < chunk.length) {
|
|
|
|
|
buf = chunk.slice(lastPos);
|
|
|
|
|
this.push(buf);
|
2026-09-15 13:00:32 +02:00
|
|
|
}
|
|
|
|
|
else if (!lastPos) {
|
2020-02-29 23:01:03 +01:00
|
|
|
this.push(chunk);
|
|
|
|
|
}
|
|
|
|
|
this.lastByte = chunk[chunk.length - 1];
|
|
|
|
|
done();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-15 13:00:32 +02:00
|
|
|
exports.default = LeWindows;
|
|
|
|
|
module.exports = exports.default;
|
|
|
|
|
Object.defineProperty(module.exports, 'default', { value: exports.default, enumerable: false, writable: true, configurable: true });
|