Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/firstandthird/bytesize
Node lib to determine byte size of a file
https://github.com/firstandthird/bytesize
Last synced: 14 days ago
JSON representation
Node lib to determine byte size of a file
- Host: GitHub
- URL: https://github.com/firstandthird/bytesize
- Owner: firstandthird
- License: mit
- Created: 2013-04-25T02:08:52.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2022-08-19T16:50:57.000Z (over 2 years ago)
- Last Synced: 2025-01-11T10:25:50.978Z (22 days ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 0
- Watchers: 13
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: HISTORY.md
- License: LICENSE
Awesome Lists containing this project
README
#bytesize
##Installation
`npm install bytesize`
##Usage
```javascript
const bytesize = require('bytesize');//string size
const size = bytesize.stringSize('1 12 3 123 123');
//size == 14//string size
const size = bytesize.stringSize('1 12 3 123 123', true);
//size == 14B//file size (returns a Promise that you can await)
try {
const size = await bytesize.fileSize(__dirname + '/fixtures/test.txt');
//size == 6660
} catch(exc) {
console.log(exc);
}//pretty file size
try {
const size = await bytesize.fileSize(__dirname + '/fixtures/test.txt', true);
//size == '6.50KB'
} catch(exc) {
console.log(exc);
}//gzip file size
try{
const size = await bytesize.gzipSize(__dirname + '/fixtures/test.txt');
//size == 190
} catch(exc) {
console.log(exc);
}//pretty gzip file size
const size = await bytesize.gzipSize(__dirname + '/fixtures/test.txt', true);
//size == '190B'
```