Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
a node.js stream implementation that creates a file on every write
JavaScript
branch: master

v1.0.1

latest commit be49086311
@mmaelzer authored
Failed to load latest commit information.
.gitignore initial commit
README.md
example.js
file-on-write.js Fix missing line that breaks absolutely everything.
package.json v1.0.1

README.md

file-on-write

A node.js stream implementation that takes a stream and creates files.

Install

npm install file-on-write

Usage

var FileOnWrite = require("file-on-write");
var writer = new FileOnWrite({
  path: './images',
  ext: '.jpg',
  filename: function(data) { return data.time; },
  transform: function(data) { return data.buffer; }
});

Options

path {String}

  • default './'
    The path to write files to.

ext {String}

  • default ''
    The file extension for the written files.

filename {Function(data)}

  • default Date.now()
    A function used to generate filenames. The data piped into the file-on-write stream will be provided as the paramater to the filename function.

sync {Boolean}

  • default false
    Write files synchronously.

context {Object}

  • default undefined
    The context to call filename() and transform() with.

transform {Function(data)}

  • default - return data
    Provide a transform method on the data passed into the file-on-write stream. Useful when only wanting to save a subset of the provided data.

Example

Here's an example of using file-on-write to write jpegs coming from an mjpeg-consumer stream:

var request = require("request");
var MjpegConsumer = require("mjpeg-consumer");
var FileOnWrite = require("file-on-write");

var writer = new FileOnWrite({ 
  path: './video',
  ext: '.jpg'
});
var consumer = new MjpegConsumer();

request("http://192.168.1.2/videostream.cgi").pipe(consumer).pipe(writer);

The MIT License

Copyright (c) 2014 Michael Maelzer

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.