1. fs-mkdirp-stream
Ensure directories exist before writing to them.
fs-mkdirp-stream
Package: fs-mkdirp-stream
Created by: gulpjs
Last modified: Thu, 22 Sep 2022 20:25:40 GMT
Version: 2.0.1
License: MIT
Downloads: 7,035,307
Repository: https://github.com/gulpjs/fs-mkdirp-stream

Install

npm install fs-mkdirp-stream
yarn add fs-mkdirp-stream

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.

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code