mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 06:29:40 +08:00
[adone] fs
* add writeFileAtomic * move is.* to fs
This commit is contained in:
64
types/adone/glosses/fs.d.ts
vendored
64
types/adone/glosses/fs.d.ts
vendored
@@ -1158,37 +1158,35 @@ declare namespace adone {
|
||||
*/
|
||||
function watch(paths: string | string[], options?: I.Watcher.ConstructorOptions): Watcher;
|
||||
|
||||
namespace is {
|
||||
/**
|
||||
* Returns true if the given path refers to a file
|
||||
*/
|
||||
function file(path: string): Promise<boolean>;
|
||||
/**
|
||||
* Returns true if the given path refers to a file
|
||||
*/
|
||||
function isFile(path: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Returns true if the given path refers to a file
|
||||
*/
|
||||
function fileSync(path: string): boolean;
|
||||
/**
|
||||
* Returns true if the given path refers to a file
|
||||
*/
|
||||
function isFileSync(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Returns true if the given path refers to a direcotry
|
||||
*/
|
||||
function directory(path: string): Promise<boolean>;
|
||||
/**
|
||||
* Returns true if the given path refers to a direcotry
|
||||
*/
|
||||
function isDirectory(path: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Returns true if the given path refers to a direcotry
|
||||
*/
|
||||
function directorySync(path: string): boolean;
|
||||
/**
|
||||
* Returns true if the given path refers to a direcotry
|
||||
*/
|
||||
function isDirectorySync(path: string): boolean;
|
||||
|
||||
/**
|
||||
* Returns true if the given path refers to an executable file
|
||||
*/
|
||||
function executable(path: string): Promise<boolean>;
|
||||
/**
|
||||
* Returns true if the given path refers to an executable file
|
||||
*/
|
||||
function isExecutable(path: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Returns true if the given path refers to an executable file
|
||||
*/
|
||||
function executableSync(path: string): boolean;
|
||||
}
|
||||
/**
|
||||
* Returns true if the given path refers to an executable file
|
||||
*/
|
||||
function isExecutableSync(path: string): boolean;
|
||||
|
||||
namespace I.Which {
|
||||
interface Options {
|
||||
@@ -1920,5 +1918,19 @@ declare namespace adone {
|
||||
* Creates a new TailWatcher instance with the given arguments
|
||||
*/
|
||||
function watchTail(filename: string, options?: I.TailWatcher.ConstructorOptions): TailWatcher;
|
||||
|
||||
namespace I {
|
||||
interface WriteFileAtomicOptions {
|
||||
chown?: {
|
||||
gid?: number;
|
||||
uid?: number;
|
||||
};
|
||||
encoding?: string | null;
|
||||
fsync?: boolean;
|
||||
mode?: number;
|
||||
}
|
||||
}
|
||||
|
||||
function writeFileAtomic(filename: string, data: Buffer | string | Uint8Array, options?: I.WriteFileAtomicOptions): Promise<void>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,13 +602,12 @@ namespace fsTests {
|
||||
}
|
||||
|
||||
namespace isTests {
|
||||
const { is } = fs;
|
||||
is.file("hello").then((x: boolean) => {});
|
||||
{ const a: boolean = is.fileSync("hello"); }
|
||||
is.directory("hello").then((x: boolean) => {});
|
||||
{ const a: boolean = is.directorySync("hello"); }
|
||||
is.executable("hello").then((x: boolean) => {});
|
||||
{ const a: boolean = is.executableSync("hello"); }
|
||||
fs.isFile("hello").then((x: boolean) => {});
|
||||
{ const a: boolean = fs.isFileSync("hello"); }
|
||||
fs.isDirectory("hello").then((x: boolean) => {});
|
||||
{ const a: boolean = fs.isDirectorySync("hello"); }
|
||||
fs.isExecutable("hello").then((x: boolean) => {});
|
||||
{ const a: boolean = fs.isExecutableSync("hello"); }
|
||||
}
|
||||
|
||||
namespace whichTests {
|
||||
@@ -944,4 +943,17 @@ namespace fsTests {
|
||||
fs.watchTail("file", { separator: /\n/ });
|
||||
fs.watchTail("file", { useWatchFile: true });
|
||||
}
|
||||
|
||||
namespace writeFileAtomicTests {
|
||||
fs.writeFileAtomic("a", "b").then(() => {});
|
||||
fs.writeFileAtomic("a", Buffer.from("b")).then(() => {});
|
||||
fs.writeFileAtomic("a", new Uint8Array(10)).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", {}).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", { chown: {} }).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", { chown: { gid: 0 } }).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", { chown: { uid: 0 } }).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", { encoding: "utf8" }).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", { fsync: false }).then(() => {});
|
||||
fs.writeFileAtomic("a", "a", { mode: 0o666 }).then(() => {});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user