mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[fs-ext] Update definition to v2 (#40439)
* [fs-ext] Update definition to v2
* Remove definitions for utime(), utimeSync().
* Add constants definition.
* Add new values of `cmd` parameter to fcntl(), fcntlSync().
* Add overrides for more accurate types of `flags` parameter in flock(), flockSync().
* Add overrides for more accurate types of `cmd` parameter in fcntl(), fcntlSync().
* Add statVFS() defintion.
* Rewrite tests.
Refs https://github.com/baudehlo/node-fs-ext/pull/90
* Use NodeJS.ErrnoException instead of Error
See 3125353321/fs-ext.cc (L366)
This commit is contained in:
parent
8fdd3ff940
commit
e8dd54730f
@ -1,25 +1,55 @@
|
||||
import fs = require('fs-ext');
|
||||
import fsExt = require('fs-ext');
|
||||
|
||||
var num:number;
|
||||
var str:string;
|
||||
const fd = 1;
|
||||
|
||||
//from node.js 'fs' module
|
||||
fs.appendFileSync(str, "data");
|
||||
|
||||
fs.flock(num, str, (err)=>{
|
||||
fsExt.flock(fd, 'sh', (err) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
});
|
||||
fs.flockSync(num, str);
|
||||
fsExt.flock(fd, fsExt.constants.LOCK_SH, (err) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
});
|
||||
fsExt.flockSync(fd, 'ex');
|
||||
fsExt.flockSync(fd, fsExt.constants.LOCK_EX);
|
||||
|
||||
fs.fcntl(num, str, num, (err, res)=>{
|
||||
fsExt.fcntl(fd, 'setlkw', fsExt.constants.F_WRLCK, (err) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
});
|
||||
fs.fcntl(num, str, (err, res)=>{
|
||||
fsExt.fcntl(fd, fsExt.constants.F_SETLKW, fsExt.constants.F_WRLCK, (err) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
});
|
||||
fs.fcntlSync(num, str, num);
|
||||
fsExt.fcntlSync(fd, fsExt.constants.F_SETLKW, fsExt.constants.F_WRLCK);
|
||||
|
||||
fs.seek(num, num, num, (err, pos)=>{
|
||||
fsExt.fcntl(fd, 'getfd', (err, flags) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
const _flags: number = flags;
|
||||
});
|
||||
fs.seekSync(num, num, num);
|
||||
fsExt.fcntl(fd, fsExt.constants.F_GETFD, (err, flags) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
const _flags: number = flags;
|
||||
});
|
||||
{
|
||||
const flags: number = fsExt.fcntlSync(fd, fsExt.constants.F_GETFD);
|
||||
}
|
||||
|
||||
fs.utime(str, num, num, (err)=>{
|
||||
fsExt.seek(fd, 2, fsExt.constants.SEEK_SET, (err, pos) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
const _pos: number = pos;
|
||||
});
|
||||
fs.utimeSync(str, num, num);
|
||||
{
|
||||
const result: number = fsExt.seekSync(fd, 2, fsExt.constants.SEEK_SET);
|
||||
}
|
||||
|
||||
fsExt.statVFS((err, stat) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
const _stat: fsExt.StatFVS = stat;
|
||||
});
|
||||
fsExt.statVFS('/some/path', (err, stat) => {
|
||||
const _err: NodeJS.ErrnoException | null = err;
|
||||
const _stat: fsExt.StatFVS = stat;
|
||||
});
|
||||
{
|
||||
const stat: fsExt.StatFVS = fsExt.statVFS();
|
||||
}
|
||||
{
|
||||
const stat: fsExt.StatFVS = fsExt.statVFS('/some/path');
|
||||
}
|
||||
|
||||
244
types/fs-ext/index.d.ts
vendored
244
types/fs-ext/index.d.ts
vendored
@ -1,101 +1,187 @@
|
||||
// Type definitions for fs-ext
|
||||
// Type definitions for fs-ext 2.0.0
|
||||
// Project: https://github.com/baudehlo/node-fs-ext
|
||||
// Definitions by: Oguzhan Ergin <https://github.com/OguzhanE>
|
||||
// Konstantin Ikonnikov <https://github.com/ikokostya>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
///<reference types="node"/>
|
||||
|
||||
|
||||
export * from "fs";
|
||||
/**
|
||||
* Asynchronous flock(2). No arguments other than a possible error are passed to the callback.
|
||||
* @param fd File descriptor.
|
||||
* @param flags Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' and correspond to the various LOCK_SH,
|
||||
* LOCK_EX, LOCK_SH | LOCK_NB, etc.
|
||||
*/
|
||||
export function flock(fd: number, flags: 'sh' | 'ex' | 'shnb' | 'exnb' | 'un', callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
export function flock(fd: number, flags: number, callback: (err: NodeJS.ErrnoException | null) => void): void;
|
||||
|
||||
/**
|
||||
* Asynchronous flock(2). No arguments other than a possible error are passed to the callback.
|
||||
* @param fd File Descriptor
|
||||
* @param flags Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' and correspond to the various LOCK_SH, LOCK_EX, LOCK_SH|LOCK_NB, etc.
|
||||
**/
|
||||
export declare function flock(fd: number, flags: string, callback: (err: Error) => void): void;
|
||||
* Synchronous flock(2). Throws an exception on error.
|
||||
* @param fd File descriptor.
|
||||
* @param flags Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' and correspond to the various LOCK_SH,
|
||||
* LOCK_EX, LOCK_SH | LOCK_NB, etc.
|
||||
*/
|
||||
export function flockSync(fd: number, flags: 'sh' | 'ex' | 'shnb' | 'exnb' | 'un'): void;
|
||||
export function flockSync(fd: number, flags: number): void;
|
||||
|
||||
/**
|
||||
* Synchronous flock(2). Throws an exception on error.
|
||||
* @param fd File Descriptor
|
||||
* @param flags Flags can be 'sh', 'ex', 'shnb', 'exnb', 'un' and correspond to the various LOCK_SH, LOCK_EX, LOCK_SH|LOCK_NB, etc.
|
||||
**/
|
||||
export declare function flockSync(fd: number, flags: string): void;
|
||||
* Asynchronous fcntl(2).
|
||||
* @param fd File descriptor.
|
||||
* @param cmd The supported commands are: 'getfd' (F_GETFD), 'setfd' (F_SETFD), 'setlk' (F_SETLK),
|
||||
* 'setlkw' (F_SETLKW), 'getlk' (F_GETLK).
|
||||
* @param arg
|
||||
*/
|
||||
export function fcntl(fd: number, cmd: 'getfd' | 'setfd' | 'setlk' | 'setlkw' | 'getlk', arg: number, callback: (err: NodeJS.ErrnoException | null, result: number) => void): void;
|
||||
export function fcntl(fd: number, cmd: number, arg: number, callback: (err: NodeJS.ErrnoException | null, result: number) => void): void;
|
||||
export function fcntl(fd: number, cmd: 'getfd' | 'setfd' | 'setlk' | 'setlkw' | 'getlk', callback: (err: NodeJS.ErrnoException | null, result: number) => void): void;
|
||||
export function fcntl(fd: number, cmd: number, callback: (err: NodeJS.ErrnoException | null, result: number) => void): void;
|
||||
|
||||
/**
|
||||
* Asynchronous fcntl(2).
|
||||
* @param fd File Descriptor
|
||||
* @param cmd The supported commands are: 'getfd' ( F_GETFD ) , 'setfd' ( F_SETFD )
|
||||
* Requiring this module adds FD_CLOEXEC to the constants module, for use with F_SETFD.
|
||||
* @param arg arg
|
||||
**/
|
||||
export declare function fcntl(fd: number, cmd: string, arg: number, callback: (err: Error, result: number) => void): void;
|
||||
* Synchronous fcntl(2). Throws an exception on error.
|
||||
* @param fd File descriptor.
|
||||
* @param cmd The supported commands are: 'getfd' (F_GETFD), 'setfd' (F_SETFD), 'setlk' (F_SETLK),
|
||||
* 'setlkw' (F_SETLKW), 'getlk' (F_GETLK).
|
||||
* @param arg arg
|
||||
* @return For a successful call, the return value depends on the operation:
|
||||
* F_GETFD
|
||||
* Value of file descriptor flags.
|
||||
* All other commands
|
||||
* Zero.
|
||||
*/
|
||||
export function fcntlSync(fd: number, cmd: 'getfd' | 'setfd' | 'setlk' | 'setlkw' | 'getlk', arg?: number): number;
|
||||
export function fcntlSync(fd: number, cmd: number, arg?: number): number;
|
||||
|
||||
/**
|
||||
* Asynchronous fcntl(2).
|
||||
* @param fd File Descriptor
|
||||
* @param cmd The supported commands are: 'getfd' ( F_GETFD ) , 'setfd' ( F_SETFD )
|
||||
* Requiring this module adds FD_CLOEXEC to the constants module, for use with F_SETFD.
|
||||
**/
|
||||
export declare function fcntl(fd: number, cmd: string, callback: (err: Error, result: number) => void): void;
|
||||
* Asynchronous lseek(2).
|
||||
* @param fd File descriptor.
|
||||
* @param offset Offset in bytes.
|
||||
* @param whence Whence can be 0 (SEEK_SET) to set the new position in bytes to offset, 1 (SEEK_CUR)
|
||||
* to set the new position to the current position plus offset bytes (can be negative), or 2
|
||||
* (SEEK_END) to set to the end of the file plus offset bytes (usually negative or zero to seek
|
||||
* to the end of the file).
|
||||
*/
|
||||
export function seek(fd: number, offset: number, whence: number, callback: (err: NodeJS.ErrnoException | null, currFilePos: number) => void): void;
|
||||
|
||||
/**
|
||||
* Synchronous fcntl(2). Throws an exception on error.
|
||||
* @param fd File Descriptor
|
||||
* @param cmd The supported commands are: 'getfd' ( F_GETFD ) , 'setfd' ( F_SETFD )
|
||||
* Requiring this module adds FD_CLOEXEC to the constants module, for use with F_SETFD.
|
||||
* @param arg arg
|
||||
* @return Returns flags
|
||||
**/
|
||||
export declare function fcntlSync(fd: number, cmd: string, arg?: number): number;
|
||||
* Synchronous lseek(2). Throws an exception on error. Returns current file position.
|
||||
* @param fd File descriptor.
|
||||
* @param offset Offset in bytes.
|
||||
* @param whence Whence can be 0 (SEEK_SET) to set the new position in bytes to offset, 1 (SEEK_CUR)
|
||||
* to set the new position to the current position plus offset bytes (can be negative), or 2
|
||||
* (SEEK_END) to set to the end of the file plus offset bytes (usually negative or zero to seek
|
||||
* to the end of the file).
|
||||
* @returns Returns current file position.
|
||||
*/
|
||||
export function seekSync(fd: number, offset: number, whence: number): number;
|
||||
|
||||
/**
|
||||
* Asynchronous lseek(2).
|
||||
* @param fd File Descriptor
|
||||
* @param offset Offset
|
||||
* @param whence
|
||||
* Whence can be 0 (SEEK_SET) to set the new position in bytes to offset, 1 (SEEK_CUR) to set the new
|
||||
* position to the current position plus offset bytes (can be negative), or 2 (SEEK_END) to set to the end
|
||||
* of the file plus offset bytes (usually negative or zero to seek to the end of the file).
|
||||
**/
|
||||
export declare function seek(fd: number, offset: number, whence: number, callback: (err: Error, currFilePos: number) => void): void;
|
||||
* Asynchronous/synchronous statvfs(2).
|
||||
* @param path Pathname of any file within the mounted file system. Default is `/`.
|
||||
*/
|
||||
export function statVFS(path: string, callback: (err: NodeJS.ErrnoException | null, stat: StatFVS) => void): void;
|
||||
export function statVFS(callback: (err: NodeJS.ErrnoException | null, stat: StatFVS) => void): void;
|
||||
export function statVFS(path?: string): StatFVS;
|
||||
|
||||
/**
|
||||
* Synchronous lseek(2). Throws an exception on error. Returns current file position.
|
||||
* @param fd File Descriptor
|
||||
* @param offset Offset
|
||||
* @param whence
|
||||
* Whence can be 0 (SEEK_SET) to set the new position in bytes to offset, 1 (SEEK_CUR) to set the new
|
||||
* position to the current position plus offset bytes (can be negative), or 2 (SEEK_END) to set to the end
|
||||
* of the file plus offset bytes (usually negative or zero to seek to the end of the file).
|
||||
* @returns Returns current file position.
|
||||
**/
|
||||
export declare function seekSync(fd: number, offset: number, whence: number): number;
|
||||
* Filesystem statistics.
|
||||
*/
|
||||
export interface StatFVS {
|
||||
/** File system block size. */
|
||||
f_bsize: number;
|
||||
/** Fragment size. */
|
||||
f_frsize: number;
|
||||
/** Size of fs in f_frsize units. */
|
||||
f_blocks: number;
|
||||
/** Number of free blocks. */
|
||||
f_bfree: number;
|
||||
/** Number of free blocks for unprivileged users. */
|
||||
f_bavail: number;
|
||||
/** Number of inodes. */
|
||||
f_files: number;
|
||||
/** Number of free inodes. */
|
||||
f_ffree: number;
|
||||
/** Number of free inodes for unprivileged users. */
|
||||
f_favail: number;
|
||||
/** Filesystem ID. */
|
||||
f_fsid: number;
|
||||
/** Mount flags. */
|
||||
f_flag: number;
|
||||
/** Maximum filename length. */
|
||||
f_namemax: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asynchronous utime(2).
|
||||
* @param path File path
|
||||
* @param atime
|
||||
* Arguments atime and mtime are in seconds as for the system call.Note that the number value of Date() is in milliseconds,
|
||||
* so to use the 'now' value with fs.utime() you would have to divide by 1000 first, e.g. Date.now()/1000
|
||||
* Just like for utime(2), the absence of the atime and mtime means 'now'.
|
||||
* @param mtime
|
||||
* Arguments atime and mtime are in seconds as for the system call.Note that the number value of Date() is in milliseconds,
|
||||
* so to use the 'now' value with fs.utime() you would have to divide by 1000 first, e.g. Date.now()/1000
|
||||
* Just like for utime(2), the absence of the atime and mtime means 'now'.
|
||||
**/
|
||||
export declare function utime(path: string, atime: number, mtime: number, callback: (err: Error) => void): void;
|
||||
export namespace constants {
|
||||
/**
|
||||
* The file offset is set to offset bytes.
|
||||
*/
|
||||
const SEEK_SET: number;
|
||||
/**
|
||||
* The file offset is set to its current location plus `offset` bytes.
|
||||
*/
|
||||
const SEEK_CUR: number;
|
||||
/**
|
||||
* The file offset is set to the size of the file plus `offset` bytes.
|
||||
*/
|
||||
const SEEK_END: number;
|
||||
|
||||
/**
|
||||
* Synchronous version of utime(). Throws an exception on error.
|
||||
* @param path File path
|
||||
* @param atime
|
||||
* Arguments atime and mtime are in seconds as for the system call.Note that the number value of Date() is in milliseconds,
|
||||
* so to use the 'now' value with fs.utime() you would have to divide by 1000 first, e.g. Date.now()/1000
|
||||
* Just like for utime(2), the absence of the atime and mtime means 'now'.
|
||||
* @param mtime
|
||||
* Arguments atime and mtime are in seconds as for the system call.Note that the number value of Date() is in milliseconds,
|
||||
* so to use the 'now' value with fs.utime() you would have to divide by 1000 first, e.g. Date.now()/1000
|
||||
* Just like for utime(2), the absence of the atime and mtime means 'now'.
|
||||
**/
|
||||
export declare function utimeSync(path: string, atime: number, mtime: number): void;
|
||||
/**
|
||||
* Place a shared lock. More than one process may hold a shared lock for a given file at a given
|
||||
* time.
|
||||
*/
|
||||
const LOCK_SH: number;
|
||||
/**
|
||||
* Place an exclusive lock. Only one process may hold an exclusive lock for a given file at a
|
||||
* given time.
|
||||
*/
|
||||
const LOCK_EX: number;
|
||||
/**
|
||||
* Remove an existing lock held by this process.
|
||||
*/
|
||||
const LOCK_UN : number;
|
||||
/**
|
||||
* A call to flock() may block if an incompatible lock is held by another process. To make a
|
||||
* nonblocking request, include LOCK_NB (by ORing) with any of the above operations.
|
||||
*/
|
||||
const LOCK_NB: number;
|
||||
|
||||
/**
|
||||
* Return (as the function result) the file descriptor flags. `arg` is ignored.
|
||||
*/
|
||||
const F_GETFD: number;
|
||||
/**
|
||||
* Set the file descriptor flags to the value specified by `arg`.
|
||||
*/
|
||||
const F_SETFD: number;
|
||||
/**
|
||||
* The close-on-exec flag.
|
||||
*/
|
||||
const FD_CLOEXEC: number;
|
||||
|
||||
/**
|
||||
* A read lock on a file.
|
||||
*/
|
||||
const F_RDLCK: number;
|
||||
/**
|
||||
* A write lock on a file.
|
||||
*/
|
||||
const F_WRLCK: number;
|
||||
/**
|
||||
* Unlock a file.
|
||||
*/
|
||||
const F_UNLCK: number;
|
||||
|
||||
/**
|
||||
* Acquire a lock (when constants F_RDLCK or F_WRLCK are specified) or release a lock (when
|
||||
* constant F_UNLCK is specified).
|
||||
*/
|
||||
const F_SETLK: number;
|
||||
/**
|
||||
* As for F_SETLK, but if a conflicting lock is held on the file, then wait for that lock to be
|
||||
* released.
|
||||
*/
|
||||
const F_SETLKW: number;
|
||||
/**
|
||||
* Test for the existence locks.
|
||||
*/
|
||||
const F_GETLK: number;
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
@ -20,4 +20,4 @@
|
||||
"index.d.ts",
|
||||
"fs-ext-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user