New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

io-extra

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

io-extra

Library to simplify file system access with promises in Node.js (Node version > 4.3.2)

  • 0.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

io-extra

Library to simplify file system access with promises in Node.js (Node version > 4.3.2)

npm Package

NOTE (2016-10-10): Node v4.3.2 or newer is required (builtin promises).

Installation

npm install --save io-extra

Usage

const io = require('io-extra');

io.file.exists('/tmp/myfile').then((exists) => {
    if (exists) {
        console.log(`File exists`);
    }
}

File Methods Directory Methods

File

resolve fullpath

path(file)

Returnes the resolved full path of a file. The file must exist.

const io = require('io-extra');

io.file.path('/tmp/myfile').then((file) => console.log('fullpath: ' + file));
// returns c:\tmp\myfile on Windows operating systems

file exists

exists(file)

Check if a file exists. Promise returns true or false whether the file exists or not.

Example:

const io = require('io-extra');

io.file.exists('/tmp/myfile').then((exists) => console.log('file exists: ' + exists));

create file

create(file)

Creates a file if it doesn't already exist. If the file is in directories that do not exist, these directories are created. Promise returns the full path of the created file.

Example:

const io = require('io-extra');

io.file.create('/tmp/myfile').then((file) => console.log('file ' + file + ' created.'));

remove file

remove(file)

Removes a file if it exists. Empty promise is returned.

Alias: delete()

Example:

const io = require('io-extra');

io.file.remove('/tmp/myfile').then(() => console.log('file removed.'));

read file

read(file, [encoding])

Reads the entire contents of a file. Promise contains the text of the file.

encoding = (optional string) specifies the type of encoding to read the file. Possible encodings are 'ascii', 'utf8', and 'base64'. If no encoding is provided, the default is utf8.

Example:

const io = require('io-extra');

io.file.read('/tmp/myfile').then((text) => console.log(text));

write file

write(file, data, [encoding])

Writes data to a file, replacing the file if it already exists. If the parent directory does not exist, it's created. Empty promise is returned.

file = (string) filepath of the file to write to.

data = (string or buffer) the data you want to write to the file.

encoding = (optional string) the encoding of the data. Possible encodings are 'ascii', 'utf8', and 'base64'. If no encoding provided, then 'utf8' is assumed.

Example:

const io = require('io-extra');

io.file.write('/tmp/myfile', 'io-extra is easy!').then(() => console.log('file written.'));

Directory

resolve directory fullpath

path(directory)

Returnes the resolved full path of a directory. The directory must exist.

const io = require('io-extra');

io.directory.path('/tmp').then((dir) => console.log('fullpath: ' + dir));
// returns c:\tmp on Windows operating systems

directory exists

exists(directory)

Check if a directory exists. Promise returns true or false whether the directory exists or not.

Example:

const io = require('io-extra');

io.directory.exists('/tmp').then((exists) => console.log('directory exists: ' + exists));

create directory

create(directory)

Creates a directory if it doesn't already exist. If the parent directory does not exist, it is created. Promise returns the full path of the created directory.

Example:

const io = require('io-extra');

io.directory.create('/tmp').then((dir) => console.log('directory ' + dir + ' created.'));

remove directory

remove(directory)

Removes a directory if it exists. Empty promise is returned.

Alias: delete()

Example:

const io = require('io-extra');

io.directory.remove('/tmp').then(() => console.log('directory removed.'));

FAQs

Package last updated on 12 Oct 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc