0.4.0 • Published 7 years ago

fs-from-object v0.4.0

Weekly downloads
6
License
MIT
Repository
github
Last release
7 years ago

fs-from-object

npm version build status dependency status license js standard style downloads per month

​:zap:​ Create files and folders in the filesystem directly from an object.

const { fsFromObject } = require('fs-from-object')

const tree = [
  { name: 'index.txt', mtime: new Date('07/07/2016'), contents: 'Hello World!' },

  {
    name: 'folder',
    contents: [
      { name: 'one.txt', contents: 'Hello World!' },
      { name: 'empty.txt' }
    ]
  }
]

fsFromObject(process.cwd(), tree)

Installation

> npm install fs-from-object

API

fsFromObject(path: String, tree: Object)

Creates the given tree representation at path.

Tree Nodes

Each node can have the following properties:

  • name: Name of the file or folder
  • contents: File or folder contents (optional)
  • mtime: Modified time of a file or directory (optional)

ephemeralFsFromObject(tree: Object, task: Function<Promise>)

Creates an ephemeral path with the given tree in it. As soon as task resolves, the folder will get deleted.

The ephemeral path has the following signature:

`${os.tmpdir()}/${uuid.v4()}`

Example

ephemeralFsFromObject([{ name: 'index.txt', contents: 'test' }], (ephemeralPath) => {
    return fs.readFile(join(ephemeralPath, 'index.txt'))
    // -> test
}).then(() => {
  // folder deleted here
})

License

MIT

0.4.0

7 years ago

0.3.0

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago