0.1.4 • Published 5 years ago

inoutjs v0.1.4

Weekly downloads
10
License
MIT
Repository
github
Last release
5 years ago

InOut.js - I/O JavaScript library

CircleCI codecov NPM version NPM downloads devDependency Status JS gzip size

Getting started

$ npm install inoutjs

or download the latest release

Usage

Load InOut.js with an ES6 import:

import io from 'inoutjs'

InOut.js read and write files by exposing the method io():

document.getElementById('file').onchange = function (e) {
  var file = e.target.files[0];
  var ioWrapper = io(file); // InOut.js file wrapper
};

Creating an empty file:

var ioWrapper = io();

Creating from blob:

var ioWrapper = io(blob);

File info

fullName() get file name including extension

var fullName = io(file).fullName(); // E.g. foo.txt

name() get file name without extension

var name = io(file).name(); // E.g. foo

ext() get file extention

var extension = io(file).ext(); // E.g. txt

type() get file content type

var type = io(file).type(); // E.g. text/plain

size() get file size

var size  = io(file).size('MB'); // Options: B, KB, MB, GB

Read file

readChunk() read chunk

io(file).readChunk(function (chunk, next) {
  console.log(chunk === undefined ? 'EOF' : chunk);
  next(); // Read next chunk
});

readLine() read line by line

io(file).readLine(function (line, next) {
  console.log(line === undefined ? 'EOF' : line);
  next(); // Read next line
});

Write to file

write() write content to file

var ioWrapper = io().write('content');

writeLine() write content to file and break line

var ioWrapper = io()
  .writeLine('content')
  .writeLine(); // Just break line

Save file

save() download the file

io(file).save();
io(file).save('foo.xml'); // Override the file name
io(file).save('foo.xml', 'application/xml'); // Override the file name and type

toFile() get JavaScript File

var file = io().toFile()

Utility functions

greaterThan() file size is greather than option

io(file).greaterThan(100, 'KB'); // Options: B, KB, MB, GB

greaterOrEqual() file size is greather or equal to option

io(file).greaterOrEqual(100, 'KB'); // Options: B, KB, MB, GB

lowerThan() file size is lower than option

io(file).lowerThan(100, 'KB'); // Options: B, KB, MB, GB

lowerOrEqual() file size is lower or equal to option

io(file).lowerOrEqual(100, 'KB'); // Options: B, KB, MB, GB

Bugs and features

Please, fell free to open a new issue on GitHub.

License

MIT

Copyright (c) 2018-present, Marx J. Moura