fs-duplex-stream

0.3.0 • Public • Published

FS Duplex Stream

Read and write to the same file simultaneously.

Installation

npm install --save fs-duplex-stream

Usage

const createDuplexStream = require('fs-duplex-stream')
const iconv = require('iconv')

const file = createDuplexStream('old-text-file.txt')
const convert = iconv.decodeStream('win1251')

// Pipe file content thru converter and back to the file
file.pipe(convert).pipe(file)

// Print message when file is fully converted
file.on('finish', () => console.log('File converted to UTF-8'))

API

createDuplexStream(path[, options])

  • path <String> | <Buffer>
  • options <Object>
    • readEncoding <String>
    • writeEncoding <String>

Returns a new DuplexStream object.

options is an object or string with the following defaults:

{
  readEncoding: null,
  writeEncoding: 'utf8'
}

The readEncoding and writeEncoding can be any one of those accepted by Buffer.

Class: DuplexStream

DuplexStream is a Duplex Stream.

duplexStream.bytesWritten

The number of bytes written so far. Does not include data that is still queued for writing.

duplexStream.path

The path to the file the stream is reading and writing from as specified in the first argument to createDuplexStream(). If path is passed as a string, then duplexStream.path will be a string. If path is passed as a Buffer, then duplexStream.path will be a Buffer.

Readme

Keywords

none

Package Sidebar

Install

npm i fs-duplex-stream

Weekly Downloads

2

Version

0.3.0

License

MIT

Last publish

Collaborators

  • linusu