开发者社区> 镜像站> NPM> fs-restore
fs-restore
take a snapshot of a file or folder to later restore it
Last updated 4 years ago by yerkopalma .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fs-restore 
SYNC missed versions from official npm registry.

fs-restore npm version

Build Status js-standard-style

Take a snapshot of a file or folder to later restore it.

Usage

var snapshot = require('fs-restore')

// take a snapshot of /src folder

var s = snapshot('/src')

// do whatever you want to the folder (delete it for example)

// restore it at the point when the snapshot was taken
s.restore()

API

var s = snapshot(path)

A function that expect the path of the file or folder to be restored later. Returns an object with a data object property and a restore function property.

s.data

An object with the representation of the folder. It is a tree data structure, each node has a type property. If type equals 'file', it also has a property data with the file contents as a stream. If type equals 'dir', it has a children property which is an object and each property of this object is the name of the file/path in this directory. So, suppose this file structure:

public/
├── images/
│   ├── img01.png
│   └── img01.png
├── data.txt
└── data.log

The object that would represent this directory would be like this

var publicFs = {
  type: 'dir',
  children: {
    'images': {
      type: 'dir',
      children: {
        'img01.png': {
          type: 'file',
          data: '...' // ReadStream
        },
        'img02.png': {
          type: 'file',
          data: '...' // ReadStream
        }
      }
    },
    'data.txt': {
      type: 'file',
      data: '...' // ReadStream
    },
    'data.log': {
      type: 'file',
      data: '...' // ReadStream
    }
  }
}

s.restore()

Restore the folder at the pointe described by s.data.

Install

$ npm install fs-restore

TODO

  • Add an option to specify a datastore, like memdb, to make restores even when the current program is finished or killed.
var snapshot = require('fs-restore')

var s = snapshot('/src', { db: require('memdb')() })

// in other program or node instance
var snapshot = require('fs-restore')

var s = snapshot('/src').restore()
  • Handle sync and async versions.

License

MIT © Yerko Palma.

Current Tags

  • 0.1.0                                ...           latest (4 years ago)

1 Versions

  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (0)
None