@delucis/filesize
v1.0.2
Published
Utility that returns human-friendly file size strings from a file path.
Downloads
15
Readme
@delucis/filesize
A minimal, asynchronous library that returns human-friendly file sizes. Wraps filesize
and uses Node’s fs.stat
to retrieve sizes from the file system.
Installation
npm install @delucis/filesize
Usage
const FS = require('@delucis/filesize')
// Use with a callback to handle the returned string.
FS('my-file.txt', function (error, size) {
if (error) {
console.error('Couldn’t get file size...')
return
}
console.log('Size of my-file.txt: ' + size);
return
})
API
@delucis/filesize(path, [options,] callback)
path
Type: string
, Buffer
, URL
The path to the file you want to get the size for, which is passed to fs.stat
.
options
Type: object
Default: {}
If included, this will be passed as filesize
’s options object.
callback
Type: function
A function to handle the returned value.
Passed arguments
- An error object, which will be
null
if all goes well. - The output of
filesize
. By default this is astring
, but can also be of other types depending on the options you pass in.
Tests
npm test