mirror of
https://github.com/dawidd6/action-send-mail.git
synced 2026-09-17 17:09:30 +07:00
67ce3558d6
Co-authored-by: dawidd6 <9713907+dawidd6@users.noreply.github.com>
28 lines
671 B
JavaScript
28 lines
671 B
JavaScript
import { Transform } from 'node:stream';
|
|
export default class LastNewline extends Transform {
|
|
constructor() {
|
|
super();
|
|
this.lastByte = false;
|
|
}
|
|
/** @internal */
|
|
_transform(chunk, encoding, done) {
|
|
if (chunk.length) {
|
|
this.lastByte = chunk[chunk.length - 1];
|
|
}
|
|
this.push(chunk);
|
|
done();
|
|
}
|
|
/** @internal */
|
|
_flush(done) {
|
|
if (this.lastByte === 0x0a) {
|
|
return done();
|
|
}
|
|
if (this.lastByte === 0x0d) {
|
|
this.push(Buffer.from('\n'));
|
|
return done();
|
|
}
|
|
this.push(Buffer.from('\r\n'));
|
|
return done();
|
|
}
|
|
}
|