Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

fs-mkdirp-stream

gulpjs8.6mMIT2.0.1

Ensure directories exist before writing to them.

fs, mkdirp, stream, mkdir, directory, directories, ensure

readme

fs-mkdirp-stream

NPM version Downloads Build Status Coveralls Status

Ensure directories exist before writing to them.

Usage

var { Readable, Writable } = require('streamx');
var mkdirpStream = require('fs-mkdirp-stream');

Readable.from([{ 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(
    new Writable({
      write: function (obj, cb) {
        // This will be called once the directory exists
        // obj === { dirname: '/path/to/my/', path: '/path/to/my/file.js' }
        cb();
      },
    })
  );

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.

changelog

Changelog

2.0.1 (2022-09-17)

Bug Fixes

  • Continue upon ENOSUP chmod failures (#19) (b63196c)

2.0.0 (2022-08-30)

⚠ BREAKING CHANGES

  • Rework errors surfaced when encountering files or symlinks (#4)
  • Ensure correct node version >=10.13.0 (fixes #10) (#12)
  • Switch to streamx & remove obj API (closes #7) (#11)
  • Stop using process.umask() & fallback to node default mode (#6)
  • Upgrade scaffold, dropping node <10 support

Features

  • Ensure correct node version >=10.13.0 (fixes #10) (#12) (e5690b4)
  • Stop using process.umask() & fallback to node default mode (#6) (f78d60b)
  • Switch to streamx & remove obj API (closes #7) (#11) (072d026)

Bug Fixes

  • Rework errors surfaced when encountering files or symlinks (#4) (3fc3dee)

Miscellaneous Chores

  • Upgrade scaffold, dropping node <10 support (bda1dee)