You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <p align="center">
  2. <a href="http://gulpjs.com">
  3. <img height="257" width="114" src="https://raw.githubusercontent.com/gulpjs/artwork/master/gulp-2x.png">
  4. </a>
  5. </p>
  6. # fs-mkdirp-stream
  7. [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![AppVeyor Build Status][appveyor-image]][appveyor-url] [![Coveralls Status][coveralls-image]][coveralls-url] [![Gitter chat][gitter-image]][gitter-url]
  8. Ensure directories exist before writing to them.
  9. ## Usage
  10. ```js
  11. var to = require('to2');
  12. var from = require('from2');
  13. var mkdirpStream = require('fs-mkdirp-stream');
  14. from.obj([{ dirname: '/path/to/my/', path: '/path/to/my/file.js' }])
  15. .pipe(mkdirpStream.obj(function(obj, callback) {
  16. // callback can take 3 arguments (err, dirname, mode)
  17. callback(null, obj.dirname);
  18. }))
  19. .pipe(to.obj(function(obj) {
  20. // This will be called once the directory exists
  21. // obj === { dirname: '/path/to/my/', path: '/path/to/my/file.js' }
  22. }));
  23. ```
  24. ## API
  25. ### `mkdirpStream(resolver)`
  26. Takes a `resolver` function or string and returns a `through2` stream.
  27. 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.
  28. 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.
  29. ### `mkdirpStream.obj(resolver)`
  30. The same as the top-level API but for object streams. See the example to see the benefit of object streams with this module.
  31. ## License
  32. MIT
  33. 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.
  34. [downloads-image]: http://img.shields.io/npm/dm/fs-mkdirp-stream.svg
  35. [npm-url]: https://npmjs.com/package/fs-mkdirp-stream
  36. [npm-image]: http://img.shields.io/npm/v/fs-mkdirp-stream.svg
  37. [travis-url]: https://travis-ci.org/gulpjs/fs-mkdirp-stream
  38. [travis-image]: http://img.shields.io/travis/gulpjs/fs-mkdirp-stream.svg?label=travis-ci
  39. [appveyor-url]: https://ci.appveyor.com/project/gulpjs/fs-mkdirp-stream
  40. [appveyor-image]: https://img.shields.io/appveyor/ci/gulpjs/fs-mkdirp-stream.svg?label=appveyor
  41. [coveralls-url]: https://coveralls.io/r/gulpjs/fs-mkdirp-stream
  42. [coveralls-image]: http://img.shields.io/coveralls/gulpjs/fs-mkdirp-stream/master.svg
  43. [gitter-url]: https://gitter.im/gulpjs/gulp
  44. [gitter-image]: https://badges.gitter.im/gulpjs/gulp.png