file-bytes

2.0.3 • Public • Published

file-bytes

npm version Build Status Build status XO code style

Get the file size of a file


Install

npm install --save file-bytes

Usage

const fileBytes = require('file-bytes');
 
fileBytes('README.md').then(size => {
  console.log(`README.md is ${size} bytes`);
});
//=> "README.md" is 1806 bytes
 
 
// sync
console.log(`README.md is ${fileBytes.sync('README.md')} bytes`);
//=> "README.md" is 1806 bytes

API

fileBytes(filename)

Returns a promise for the filename's file size as a number.

fileBytes.sync(filename)

Return's the filename's file size as a number.

filename

Type: string


Examples

const fileBytes = require('file-bytes');
const prettyBytes = require('pretty-bytes');
 
console.log(prettyBytes(fileBytes.sync('example.txt')));
//=> 1.34 kB

  • Get the file sizes of everything in the current repo with glob
const fileBytes = require('file-bytes');
const glob = require('glob');
 
glob('./*', (err, files) => {
  // files is an array of filenames.
  for (let file of files) {
    const size = fileBytes.sync(file);
    console.log(`"${file}" is ${size} bytes`);
  }
});
//=> "README.md" is 1806 bytes
//=> "package.json" is 122 bytes
//=> "index.js" is 497 bytes

License

MIT © Dawson Botsford

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.3
    29
    • latest

Version History

Package Sidebar

Install

npm i file-bytes

Weekly Downloads

34

Version

2.0.3

License

MIT

Last publish

Collaborators

  • dawsonbotsford