@delucis/filesize

Utility that returns human-friendly file size strings from a file path.

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
00Jun 16, 2019Jun 26, 2017Minified + gzip package size for @delucis/filesize in KB

Readme

@delucis/filesize

Build Status Coverage Status

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
  1. An error object, which will be null if all goes well.
  2. The output of filesize. By default this is a string, but can also be of other types depending on the options you pass in.

Tests

npm test

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.