use BufferEncoding type for file.enc

This commit is contained in:
Conduitry 2019-05-31 11:30:13 -04:00
parent 13b11f8cf4
commit 5a7951ef0b
2 changed files with 4 additions and 4 deletions

View File

@ -12,7 +12,7 @@ export default class File {
// stats of file
stats: fs.Stats = null;
// encoding
private _enc: string = 'utf8';
private _enc: BufferEncoding = 'utf8';
// Buffer of file contents
private _bytes: Buffer = null;
// string of file contents
@ -80,11 +80,11 @@ export default class File {
this.path = (old ? this._path.slice(0, -old.length) : this._path) + ext;
}
get enc(): string {
get enc(): BufferEncoding {
return this._enc;
}
set enc(enc: string) {
set enc(enc: BufferEncoding) {
if (!Buffer.isEncoding(enc)) {
throw new TypeError('file.enc must be a supported encoding');
}

2
types/index.d.ts vendored
View File

@ -18,7 +18,7 @@ export class File {
dir: string;
filename: string;
ext: string;
enc: string;
enc: BufferEncoding;
bytes: Buffer;
text: string;
}