UNPKG

496 BJavaScriptView Raw
1/*
2 Copyright 2018 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9const fs = require('fs');
10
11const errors = require('./errors');
12
13module.exports = (file) => {
14 try {
15 const stat = fs.statSync(file);
16 if (!stat.isFile()) {
17 return null;
18 }
19 return stat.size;
20 } catch (err) {
21 throw new Error(errors['unable-to-get-file-size'] + ` '${err.message}'`);
22 }
23};