Skip to content

An easy way to create readable stream that loops over file contents infinitely.

License

Notifications You must be signed in to change notification settings

andrewshatnyy/infinite-file-stream

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

infinite-file-stream

Build Status

Minimalistic infinite file stream.

An easy way to create readable stream that loops over file contents infinitely.

Install

npm i infinite-file-stream

Use

  • Pass in file [string] and optional encoding [string] options.
  • Use it as a readable node Stream

Can pipe

const IFS = require('infinite-file-stream');

const stream = new FileStreamer({ file });
stream.pipe(process.stdout);

Or, emit events

const IFS = require('infinite-file-stream');

const stream = new FileStreamer({ file });
stream.on('data' console.log.bind(console));

Useful with test event servers to emit data per line

const IFS = require('infinite-file-stream');
const through = require('through');
const koa = require('koa');
const app = koa();

const file = './some/sample.txt';

app.use(function *response() {
  this.type = 'text/event-stream; charset=utf-8';
  this.set('Cache-Control', 'no-cache');
  this.set('Connection', 'keep-alive');

  this.body = (new IFS({ file }))
    .on('error', console.error.bind(console))
    .pipe(es.split('\n'))
    .pipe(through(send, end));

  const socket = this.socket;
  function close() {
    socket.removeListener('error', close);
    socket.removeListener('close', close);
  }
  socket.on('error', close);
  socket.on('close', close);
});

app.listen(9000);

License

MIT

About

An easy way to create readable stream that loops over file contents infinitely.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages