Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

build-file-tree-from-object

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

build-file-tree-from-object

Asynchronously build directories and write files from an object

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

build-file-tree-from-object

Build Status npm version Coverage Status

Asynchronously build directories and write files from an object.

Install

npm install build-file-tree-from-object

Usage

const build = require('build-file-tree-from-object')

const tree = {
  'some.file': 'string value means:\n  file content\n',
  'file.dat' : Buffer.from('Buffer value also means:\n  file content\n'),
  'some_dir' : { // Object value means directory.
    'sub.file': 'another file\ninside the new dir\n',
    'dirdir': {
      'itty.bitty.file': 'itty bitty'
    },
    'dir2': { // can have as many directories in a directory as you want...
      // even if there's no keys inside `dir2` will still be created.
    },
    'empty.file': '', // use empty string to get an empty file.
  },
}

// build the tree starting at `process.cwd()`:
build({
  tree,
  done: error => { // callback required.
    // called when all async processes are completed. tree built.
    // called when mkdir() errors (other than 'EEXIST').
    // called with error from writeFile() or invalid value
    // when there's no error callback (which quits the processing).
  },
})

// specify where to build the tree by providing `root`:
build({
  tree,
  root: 'some/dir', // optional; defaults to process.cwd()
  done: error => { }
})

// if you want writeFile() errors and invalid `value` errors
// reported without quitting the processing,
// then provide an `error` callback:
build({
  tree,
  error: error => { // optional.
    // receives:
    // 1. invalid value errors
    // 2. writeFile() errors

    // Does NOT receive mkdir() errors. those go to done().
  },
  done: error => { }
})

// NOTE: errors from mkdir() always cause it to quit processing.

MIT License

Keywords

FAQs

Package last updated on 01 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc