Skip to content

Commit

Permalink
Add fileSync() method (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
tikotzky authored and sindresorhus committed Jul 5, 2018
1 parent 2c92b28 commit 43fcdfa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Expand Up @@ -54,3 +54,8 @@ module.exports.file = (path, options) => {
gzipStream.on('gzip-size', resolve);
});
};

module.exports.fileSync = (path, options) => {
const data = fs.readFileSync(path);
return module.exports.sync(data, options);
};
4 changes: 4 additions & 0 deletions readme.md
Expand Up @@ -56,6 +56,10 @@ Returns a `Promise` for the size of the file.

Type: `string`

### gzipSize.fileSync(path, [options])

Returns the size of the file.


## Related

Expand Down
4 changes: 4 additions & 0 deletions test.js
Expand Up @@ -54,6 +54,10 @@ test('file - get the gzipped size', async t => {
t.true(await m.file('test.js') < fixture.length);
});

test('fileSync - get the gzipped size', t => {
t.is(m.fileSync('test.js'), m.sync(fixture));
});

test('file - match async version', async t => {
t.is(await m.file('test.js'), await m(fixture));
});

0 comments on commit 43fcdfa

Please sign in to comment.