inoutjs v0.1.4
InOut.js - I/O JavaScript library
Getting started
$ npm install inoutjsor 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.txtname() get file name without extension
var name = io(file).name(); // E.g. fooext() get file extention
var extension = io(file).ext(); // E.g. txttype() get file content type
var type = io(file).type(); // E.g. text/plainsize() get file size
var size = io(file).size('MB'); // Options: B, KB, MB, GBRead 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 lineSave 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 typetoFile() 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, GBgreaterOrEqual() file size is greather or equal to option
io(file).greaterOrEqual(100, 'KB'); // Options: B, KB, MB, GBlowerThan() file size is lower than option
io(file).lowerThan(100, 'KB'); // Options: B, KB, MB, GBlowerOrEqual() file size is lower or equal to option
io(file).lowerOrEqual(100, 'KB'); // Options: B, KB, MB, GBBugs and features
Please, fell free to open a new issue on GitHub.
License
Copyright (c) 2018-present, Marx J. Moura
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago