$ npm install inoutjs
or download the latest release
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);
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
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()
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()
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()
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
Please, fell free to open a new issue on GitHub.
Copyright (c) 2018-present, Marx J. Moura