New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

disk-action

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

disk-action

Implement standard disk actions

latest
Source
npmnpm
Version
0.2.1
Version published
Maintainers
1
Created
Source

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:

  • read() read a file
  • touch() create empty file
  • write() similar to create() for backward compatibility
  • create() create a file or directory
  • append() append content to a file
  • copy() copy a file/directory
  • move() move a file directory
  • replace() replace string in file
  • delete() delete file/directory

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

Keywords

CoffeeScript

FAQs

Package last updated on 17 Mar 2017

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