lib-utils-ts
Version:
<img src="https://img.shields.io/npm/v/lib-utils-ts"/> <img src="https://img.shields.io/snyk/vulnerabilities/npm/lib-utils-ts"/> <img src="https://img.shields.io/npm/l/lib-utils-ts"/> <img src="https://img.shields.io/github/languages/top/devGnode/lib-util
22 lines (19 loc) • 594 B
text/typescript
import {Path} from "./Path";
import {File} from "./File";
import * as fs from "fs";
import {IOException} from "./IOException";
export abstract class Files{
/***
* @param {File | Path} file
* @return {number}
*/
public static size(file:File|Path):number{
if(file instanceof Path) file = file.toFile();
if(file instanceof File){
if(file.isDirectory()) throw new IOException(`${file.toString()} is not a file !`);
if(file.isFile()) fs.statSync('path/to/file').size;
}
return -1;
}
private constructor() {}
}