Git Product home page Git Product logo

fs-mkdirp-stream's Introduction

fs-mkdirp-stream

NPM version Downloads Build Status Coveralls Status

Ensure directories exist before writing to them.

Usage

var to = require('to2');
var from = require('from2');
var mkdirpStream = require('fs-mkdirp-stream');

from
  .obj([{ dirname: '/path/to/my/', path: '/path/to/my/file.js' }])
  .pipe(
    mkdirpStream(function (obj, callback) {
      // callback can take 3 arguments (err, dirname, mode)
      callback(null, obj.dirname);
    })
  )
  .pipe(
    to.obj(function (obj) {
      // This will be called once the directory exists
      // obj === { dirname: '/path/to/my/', path: '/path/to/my/file.js' }
    })
  );

API

mkdirpStream(resolver)

Takes a resolver function or string and returns a streamx.Transform stream.

If the resolver is a function, it will be called once per chunk with the signature (chunk, callback). The callback(error, dirpath, mode) must be called with the dirpath to be created as the 2nd parameter or an error as the 1st parameter; optionally with a mode as the 3rd parameter.

If the resolver is a string, it will be created/ensured for each chunk (e.g. if it were deleted between chunks, it would be recreated). When using a string, a custom mode can't be used.

License

MIT

Contains a custom implementation of mkdirp originally based on https://github.com/substack/node-mkdirp (Licensed MIT/X11 - Copyright 2010 James Halliday) with heavy modification to better support custom modes.

fs-mkdirp-stream's People

Contributors

coreyfarrell avatar erikkemperman avatar phated avatar sttk avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.