Skip to content

gourmetjs/stream-normalize-eol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stream-normalize-eol

A duplex stream that normalizes the end of line characters.

API

var normalize = require("stream-normalize-eol");
var stream = normalize("\n");

// pipe input and output streams to `stream`.

normalize(format)

Returns a duplex stream that normalizes the end of line characters to the desired format. format is a string that can be one of the following:

  • "\n": Unix format (LF) / default
  • "\r\n": Windows format (CR/LF)
  • "\r": Old Mac format (CR)

Internally, this stream assumes that the input data is encoded as utf8. If you supply non-utf8 encoded multi-byte data, it will not be processed correctly.

Example

var fs = require("fs");
var normalize = require("stream-normalize-eol");

fs.writeFileSync("hello.txt", "Hello\nWorld", "utf8");

var input = fs.createReadStream("hello.txt");
var stream = normalize("\r\n");

stream.on("data", function(chunk) {
  console.log(JSON.stringify(chunk.toString()));
});

input.pipe(stream);

// prints "Hello\r\nWorld"

License

MIT

About

A duplex stream that normalizes the end of line characters

Resources

Stars

Watchers

Forks

Packages

No packages published