Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
34 lines
670 B
Plaintext
34 lines
670 B
Plaintext
'use strict';
|
|
|
|
const Transform = require('stream').Transform;
|
|
|
|
class LastNewline extends Transform {
|
|
constructor() {
|
|
super();
|
|
this.lastByte = false;
|
|
}
|
|
|
|
_transform(chunk, encoding, done) {
|
|
if (chunk.length) {
|
|
this.lastByte = chunk[chunk.length - 1];
|
|
}
|
|
|
|
this.push(chunk);
|
|
done();
|
|
}
|
|
|
|
_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();
|
|
}
|
|
}
|
|
|
|
module.exports = LastNewline;
|