disk-action

0.2.1 • Public • Published

disk-action

NPM

Downloads per month npm version Build Status Dependencies

Easy to use module in order to create / delete / modify files and directory. All unexistent directories will be create 'on-the-fly', and delete works for either file or directory. ** BE CAREFUL ** when specifying directory: all content will be erased !!

Important: This package is NOT backward compatible with 0.1.x versions... Be careful if you update your npm project...

Install

Install with npm:

  npm install disk-action

Basic Usage

Require the module:

  Disk = require 'disk-action'

Initialize with encoding (default is 'utf-8'):

  disk = new Disk('utf-8')

Read a file:

  disk.read
    filename: 'directory/not/created/hello.txt'
    cb: (data) ->
      console.log data

Methods available:

Methods usage:

Read a file:

  disk.read
    filename: 'directory/not/created/hello.txt'
    cb: (data) ->
      console.log data

Create file:

  disk.create
    filename: 'directory/not/created/hello.txt'
    content: 'I like coffee'
    cb: () ->
      console.log 'File created'

Create file with content:

  disk.create
    filename: 'directory/not/created/hello.txt'
    content: 'I like coffee'

Create directory:

  disk.create
    dirname: 'another/directory'

Append to file:

  disk.append
    filename: 'directory/not/created/hello.txt'
    content: 'But JS is not my best friend... ;)'

Copy files:

  disk.copy
    source: 'directory/not/created/hello.txt'
    destination: 'another/directory/hello2.txt'

Move files:

  disk.move
    source: 'directory/not/created/hello.txt'
    destination: 'another/directory/hello2.txt'

Replace content in file:

  disk.replace
    filename: 'directory/not/created/hello.txt'
    to_replace: 'coffee'
    replace_with: 'CoffeeScript'

Delete file or directory:

  disk.delete
    filename: 'directory/not/created/hello.txt'

Extended usage

All methods supports an optional callback parameter:

  disk.write
    filename: 'directory/not/created/hello.txt'
    content: 'I like coffee'
    cb: do_something()

or:

  disk.read
    filename: 'directory/not/created/hello.txt'
    cb: (data) ->
      console.log data

Run tests

You can run unit-tests using mocha with:

  npm test

Package Sidebar

Install

npm i disk-action

Weekly Downloads

2

Version

0.2.1

License

Apache-2.0

Last publish

Collaborators

  • x62en