source: node_modules/nodemailer/lib/mime-node/le-windows.js@ 62b2964

finki-main main
Last change on this file since 62b2964 was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1'use strict';
2
3const stream = require('stream');
4const Transform = stream.Transform;
5
6/**
7 * Ensures that only <CR><LF> sequences are used for linebreaks
8 *
9 * @param {Object} options Stream options
10 */
11class LeWindows extends Transform {
12 constructor(options) {
13 super(options);
14 // init Transform
15 this.options = options || {};
16 this.lastByte = false;
17 }
18
19 /**
20 * Escapes dots
21 */
22 _transform(chunk, encoding, done) {
23 let buf;
24 let lastPos = 0;
25
26 for (let i = 0, len = chunk.length; i < len; i++) {
27 if (chunk[i] === 0x0a) {
28 // \n
29 if ((i && chunk[i - 1] !== 0x0d) || (!i && this.lastByte !== 0x0d)) {
30 if (i > lastPos) {
31 buf = chunk.slice(lastPos, i);
32 this.push(buf);
33 }
34 this.push(Buffer.from('\r\n'));
35 lastPos = i + 1;
36 }
37 }
38 }
39
40 if (lastPos && lastPos < chunk.length) {
41 buf = chunk.slice(lastPos);
42 this.push(buf);
43 } else if (!lastPos) {
44 this.push(chunk);
45 }
46
47 this.lastByte = chunk[chunk.length - 1];
48 done();
49 }
50}
51
52module.exports = LeWindows;
Note: See TracBrowser for help on using the repository browser.