disk-action
Implement standard disk actions
Last updated 3 years ago by x62en .
Apache-2.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install disk-action 
SYNC missed versions from official npm registry.

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

Current Tags

  • 0.2.1                                ...           latest (3 years ago)

7 Versions

  • 0.2.1                                ...           3 years ago
  • 0.2.0                                ...           3 years ago
  • 0.1.4                                ...           5 years ago
  • 0.1.3                                ...           5 years ago
  • 0.1.2                                ...           5 years ago
  • 0.1.1                                ...           5 years ago
  • 0.1.0                                ...           5 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (4)
Dependents (2)

Copyright 2014 - 2016 © taobao.org |