-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add withFileTypes option support for readdir and readdirSync
Add `withFileTypes` option support for `fs.readdir` and `fs.readdirSync`. Add new `fs.Dirent` class (obviously) which is similar to `fs.Stats` but also need the `encoding` option for constructing the name. Move all encoding related types and functions to new `encoding.ts` file.
- Loading branch information
1 parent
0c854ec
commit f03f3d1
Showing
6 changed files
with
130 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import errors = require('./internal/errors'); | ||
|
||
export type TDataOut = string | Buffer; // Data formats we give back to users. | ||
export type TEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64' | 'latin1' | 'binary' | 'hex'; | ||
export type TEncodingExtended = TEncoding | 'buffer'; | ||
|
||
export const ENCODING_UTF8: TEncoding = 'utf8'; | ||
|
||
export function assertEncoding(encoding: string) { | ||
if(encoding && !Buffer.isEncoding(encoding)) | ||
throw new errors.TypeError('ERR_INVALID_OPT_VALUE_ENCODING', encoding); | ||
} | ||
|
||
export function strToEncoding(str: string, encoding?: TEncodingExtended): TDataOut { | ||
if(!encoding || (encoding === ENCODING_UTF8)) return str; // UTF-8 | ||
if(encoding === 'buffer') return new Buffer(str); // `buffer` encoding | ||
return (new Buffer(str)).toString(encoding); // Custom encoding | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters