finki-main
main
|
Last change
on this file since 81bc7da was 81bc7da, checked in by Klimentina Efremova <klimentina08642@…>, 3 months ago |
|
Initial commit
|
-
Property mode
set to
100644
|
|
File size:
961 bytes
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | const stream = require('stream');
|
|---|
| 4 | const Transform = stream.Transform;
|
|---|
| 5 |
|
|---|
| 6 | /**
|
|---|
| 7 | * Ensures that only <LF> is used for linebreaks
|
|---|
| 8 | *
|
|---|
| 9 | * @param {Object} options Stream options
|
|---|
| 10 | */
|
|---|
| 11 | class LeWindows extends Transform {
|
|---|
| 12 | constructor(options) {
|
|---|
| 13 | super(options);
|
|---|
| 14 | // init Transform
|
|---|
| 15 | this.options = options || {};
|
|---|
| 16 | }
|
|---|
| 17 |
|
|---|
| 18 | /**
|
|---|
| 19 | * Escapes dots
|
|---|
| 20 | */
|
|---|
| 21 | _transform(chunk, encoding, done) {
|
|---|
| 22 | let buf;
|
|---|
| 23 | let lastPos = 0;
|
|---|
| 24 |
|
|---|
| 25 | for (let i = 0, len = chunk.length; i < len; i++) {
|
|---|
| 26 | if (chunk[i] === 0x0d) {
|
|---|
| 27 | // \n
|
|---|
| 28 | buf = chunk.slice(lastPos, i);
|
|---|
| 29 | lastPos = i + 1;
|
|---|
| 30 | this.push(buf);
|
|---|
| 31 | }
|
|---|
| 32 | }
|
|---|
| 33 | if (lastPos && lastPos < chunk.length) {
|
|---|
| 34 | buf = chunk.slice(lastPos);
|
|---|
| 35 | this.push(buf);
|
|---|
| 36 | } else if (!lastPos) {
|
|---|
| 37 | this.push(chunk);
|
|---|
| 38 | }
|
|---|
| 39 | done();
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | module.exports = LeWindows;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.