From 07668e754637c04c0ce1a6f106b816051d4de010 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 29 Aug 2016 20:06:45 -0700 Subject: [PATCH] [node plugin] Update definitions for fs --- plugin/node.js | 350 ++++++++++++++++++++++++++-------------- test/cases/node/main.js | 2 +- 2 files changed, 233 insertions(+), 119 deletions(-) diff --git a/plugin/node.js b/plugin/node.js index 0536beba..a998142c 100644 --- a/plugin/node.js +++ b/plugin/node.js @@ -1313,89 +1313,109 @@ }, fs: { "!url": "https://nodejs.org/api/fs.html", - "!doc": "File I/O is provided by simple wrappers around standard POSIX functions. To use this module do require('fs').\nAll the methods have asynchronous and synchronous forms.", + "!doc": "File I/O is provided by simple wrappers around standard POSIX functions. To use this module do require('fs'). All the methods have asynchronous and synchronous forms.", + access: { + "!type": "fn(path: string|+Buffer, mode?: number, callback: fn(err: +Error))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_access_path_mode_callback", + "!doc": "Tests a user's permissions for the file or directory specified by path. The mode argument is an optional integer that specifies the accessibility checks to be performed. The following constants define the possible values of mode. It is possible to create a mask consisting of the bitwise OR of two or more values." + }, + accessSync: { + "!type": "fn(path: string|+Buffer, mode?: number)", + "!url": "https://nodejs.org/api/fs.html#fs_fs_accesssync_path_mode", + "!doc": "Synchronous version of fs.access(). This throws if any accessibility checks fail, and does nothing otherwise." + }, appendFile: { - "!type": "fn(filename: string, data: string|+Buffer, encoding?: string, callback?: fn())", - "!url": "https://nodejs.org/api/fs.html#fs_fs_appendfile_filename_data_options_callback", - "!doc": "Asynchronously append data to a file, creating the file if it not yet exists. data can be a string or a buffer." + "!type": "fn(file: string|+Buffer|number, data: string|+Buffer, options?: ?, callback: fn(err: +Error))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_appendfile_file_data_options_callback", + "!doc": "Asynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a buffer." }, appendFileSync: { - "!type": "fn(filename: string, data: string|+Buffer, encoding?: string)", - "!url": "https://nodejs.org/api/fs.html#fs_fs_appendfilesync_filename_data_options", - "!doc": "The synchronous version of fs.appendFile." + "!type": "fn(file: string|+Buffer|number, data: string|+Buffer, options?: ?)", + "!url": "https://nodejs.org/api/fs.html#fs_fs_appendfilesync_file_data_options", + "!doc": "The synchronous version of fs.appendFile(). Returns undefined." }, chmod: { - "!type": "fn(path: string, mode: string, callback?: fn())", + "!type": "fn(path: string|+Buffer, mode: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_chmod_path_mode_callback", "!doc": "Asynchronous chmod(2). No arguments other than a possible exception are given to the completion callback." }, chmodSync: { - "!type": "fn(path: string, mode: string)", + "!type": "fn(path: string|+Buffer, mode: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_chmodsync_path_mode", - "!doc": "Synchronous chmod(2)." + "!doc": "Synchronous chmod(2). Returns undefined." }, chown: { - "!type": "fn(path: string, uid: number, gid: number, callback?: fn())", + "!type": "fn(path: string|+Buffer, uid: number, gid: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_chown_path_uid_gid_callback", "!doc": "Asynchronous chown(2). No arguments other than a possible exception are given to the completion callback." }, chownSync: { - "!type": "fn(path: string, uid: number, gid: number)", + "!type": "fn(path: string|+Buffer, uid: number, gid: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_chownsync_path_uid_gid", - "!doc": "Synchronous chown(2)." + "!doc": "Synchronous chown(2). Returns undefined." }, close: { - "!type": "fn(fd: number, callback?: fn())", + "!type": "fn(fd: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_close_fd_callback", "!doc": "Asynchronous close(2). No arguments other than a possible exception are given to the completion callback." }, closeSync: { "!type": "fn(fd: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_closesync_fd", - "!doc": "Synchronous close(2)." + "!doc": "Synchronous close(2). Returns undefined." }, createReadStream: { - "!type": "fn(path: string, options?: ?) -> +stream.Readable", + "!type": "fn(path: string|+Buffer, options?: ?) -> +fs.ReadStream", "!url": "https://nodejs.org/api/fs.html#fs_fs_createreadstream_path_options", - "!doc": "Returns a new ReadStream object." + "!doc": "Returns a new ReadStream object. (See Readable Stream)." }, createWriteStream: { - "!type": "fn(path: string, options?: ?) -> +stream.Writable", + "!type": "fn(path: string|+Buffer, options?: ?) -> +fs.WriteStream", "!url": "https://nodejs.org/api/fs.html#fs_fs_createwritestream_path_options", - "!doc": "Returns a new WriteStream object." + "!doc": "Returns a new WriteStream object. (See Writable Stream)." }, exists: { - "!type": "fn(path: string, callback?: fn(exists: bool))", + "!type": "fn(path: string|+Buffer, callback: fn(exists: bool))", "!url": "https://nodejs.org/api/fs.html#fs_fs_exists_path_callback", - "!doc": "Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false." + "!doc": "Test whether or not the given path exists by checking with the file system. Then call the callback argument with either true or false. Example:" }, existsSync: { - "!type": "fn(path: string) -> bool", + "!type": "fn(path: string|+Buffer) -> bool", "!url": "https://nodejs.org/api/fs.html#fs_fs_existssync_path", - "!doc": "Synchronous version of fs.exists." + "!doc": "Stability: 0 - Deprecated: Use fs.statSync() or fs.accessSync() instead." }, fchmod: { - "!type": "fn(fd: number, mode: string, callback?: fn())", + "!type": "fn(fd: number, mode: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_fchmod_fd_mode_callback", "!doc": "Asynchronous fchmod(2). No arguments other than a possible exception are given to the completion callback." }, fchmodSync: { - "!type": "fn(fd: number, mode: string)", + "!type": "fn(fd: number, mode: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_fchmodsync_fd_mode", - "!doc": "Synchronous fchmod(2)." + "!doc": "Synchronous fchmod(2). Returns undefined." }, fchown: { - "!type": "fn(fd: number, uid: number, gid: number, callback?: fn())", + "!type": "fn(fd: number, uid: number, gid: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_fchown_fd_uid_gid_callback", "!doc": "Asynchronous fchown(2). No arguments other than a possible exception are given to the completion callback." }, fchownSync: { "!type": "fn(fd: number, uid: number, gid: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_fchownsync_fd_uid_gid", - "!doc": "Synchronous fchown(2)." + "!doc": "Synchronous fchown(2). Returns undefined." + }, + fdatasync: { + "!type": "fn(fd: number, callback: fn(err: +Error))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_fdatasync_fd_callback", + "!doc": "Asynchronous fdatasync(2). No arguments other than a possible exception are given to the completion callback." + }, + fdatasyncSync: { + "!type": "fn(fd: number)", + "!url": "https://nodejs.org/api/fs.html#fs_fs_fdatasyncsync_fd", + "!doc": "Synchronous fdatasync(2). Returns undefined." }, fstat: { - "!type": "fn(fd: number, callback?: fn(err: +Error, stats: +fs.Stats) -> ?) -> +fs.Stats", + "!type": "fn(fd: number, callback: fn(err: +Error, stats: +fs.Stats))", "!url": "https://nodejs.org/api/fs.html#fs_fs_fstat_fd_callback", "!doc": "Asynchronous fstat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd." }, @@ -1405,256 +1425,288 @@ "!doc": "Synchronous fstat(2). Returns an instance of fs.Stats." }, fsync: { - "!type": "fn(fd: number, callback?: fn())", + "!type": "fn(fd: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_fsync_fd_callback", "!doc": "Asynchronous fsync(2). No arguments other than a possible exception are given to the completion callback." }, fsyncSync: { "!type": "fn(fd: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_fsyncsync_fd", - "!doc": "Synchronous fsync(2)." + "!doc": "Synchronous fsync(2). Returns undefined." }, ftruncate: { - "!type": "fn(fd: number, len: number, callback?: fn())", + "!type": "fn(fd: number, len: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_ftruncate_fd_len_callback", "!doc": "Asynchronous ftruncate(2). No arguments other than a possible exception are given to the completion callback." }, ftruncateSync: { "!type": "fn(fd: number, len: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_ftruncatesync_fd_len", - "!doc": "Synchronous ftruncate(2)." + "!doc": "Synchronous ftruncate(2). Returns undefined." }, futimes: { - "!type": "fn(fd: number, atime: number, mtime: number, callback?: fn())", + "!type": "fn(fd: number, atime: number, mtime: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_futimes_fd_atime_mtime_callback", "!doc": "Change the file timestamps of a file referenced by the supplied file descriptor." }, futimesSync: { "!type": "fn(fd: number, atime: number, mtime: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_futimessync_fd_atime_mtime", - "!doc": "Change the file timestamps of a file referenced by the supplied file descriptor." + "!doc": "Synchronous version of fs.futimes(). Returns undefined." }, lchmod: { - "!type": "fn(path: string, mode: number, callback?: fn())", + "!type": "fn(path: string|+Buffer, mode: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_lchmod_path_mode_callback", "!doc": "Asynchronous lchmod(2). No arguments other than a possible exception are given to the completion callback." }, lchmodSync: { - "!type": "fn(path: string, mode: string)", + "!type": "fn(path: string|+Buffer, mode: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_lchmodsync_path_mode", - "!doc": "Synchronous lchmod(2)." + "!doc": "Synchronous lchmod(2). Returns undefined." }, lchown: { - "!type": "fn(path: string, uid: number, gid: number, callback?: fn())", + "!type": "fn(path: string|+Buffer, uid: number, gid: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_lchown_path_uid_gid_callback", "!doc": "Asynchronous lchown(2). No arguments other than a possible exception are given to the completion callback." }, lchownSync: { - "!type": "fn(path: string, uid: number, gid: number)", + "!type": "fn(path: string|+Buffer, uid: number, gid: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_lchownsync_path_uid_gid", - "!doc": "Synchronous lchown(2)." + "!doc": "Synchronous lchown(2). Returns undefined." }, link: { - "!type": "fn(srcpath: string, dstpath: string, callback?: fn())", + "!type": "fn(srcpath: string|+Buffer, dstpath: string|+Buffer, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_link_srcpath_dstpath_callback", "!doc": "Asynchronous link(2). No arguments other than a possible exception are given to the completion callback." }, linkSync: { - "!type": "fn(srcpath: string, dstpath: string)", + "!type": "fn(srcpath: string|+Buffer, dstpath: string|+Buffer)", "!url": "https://nodejs.org/api/fs.html#fs_fs_linksync_srcpath_dstpath", - "!doc": "Synchronous link(2)." + "!doc": "Synchronous link(2). Returns undefined." }, lstat: { - "!type": "fn(path: string, callback?: fn(err: +Error, stats: +fs.Stats) -> ?) -> +fs.Stats", + "!type": "fn(path: string|+Buffer, callback: fn(err: +Error, stats: +fs.Stats))", "!url": "https://nodejs.org/api/fs.html#fs_fs_lstat_path_callback", "!doc": "Asynchronous lstat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. lstat() is identical to stat(), except that if path is a symbolic link, then the link itself is stat-ed, not the file that it refers to." }, lstatSync: { - "!type": "fn(path: string) -> +fs.Stats", + "!type": "fn(path: string|+Buffer) -> +fs.Stats", "!url": "https://nodejs.org/api/fs.html#fs_fs_lstatsync_path", "!doc": "Synchronous lstat(2). Returns an instance of fs.Stats." }, mkdir: { - "!type": "fn(path: string, mode?: ?, callback?: fn())", + "!type": "fn(path: string|+Buffer, mode?: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_mkdir_path_mode_callback", - "!doc": "Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0777." + "!doc": "Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0o777." }, mkdirSync: { - "!type": "fn(path: string, mode?: string)", + "!type": "fn(path: string|+Buffer, mode?: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_mkdirsync_path_mode", - "!doc": "Synchronous mkdir(2)." + "!doc": "Synchronous mkdir(2). Returns undefined." + }, + mkdtemp: { + "!type": "fn(prefix: string, options?: ?, callback: fn(err: +Error, folder: string))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_mkdtemp_prefix_options_callback", + "!doc": "Creates a unique temporary directory." + }, + mkdtempSync: { + "!type": "fn(prefix: string, options?: ?) -> string", + "!url": "https://nodejs.org/api/fs.html#fs_fs_mkdtempsync_prefix_options", + "!doc": "The synchronous version of fs.mkdtemp(). Returns the created folder path." }, open: { - "!type": "fn(path: string, flags: string, mode?: string, callback?: fn(err: +Error, fd: number))", + "!type": "fn(path: string|+Buffer, flags: string|number, mode?: number, callback: fn(err: +Error, fd: number))", "!url": "https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback", - "!doc": "Asynchronous file open." + "!doc": "Asynchronous file open. See open(2). flags can be:" }, openSync: { - "!type": "fn(path: string, flags: string, mode?: string) -> number", + "!type": "fn(path: string|+Buffer, flags: string|number, mode?: number) -> number", "!url": "https://nodejs.org/api/fs.html#fs_fs_opensync_path_flags_mode", - "!doc": "Synchronous open(2)." + "!doc": "Synchronous version of fs.open(). Returns an integer representing the file descriptor." }, read: { - "!type": "fn(fd: number, buffer: +Buffer, offset: number, length: number, position: number, callback?: fn(err: +Error, bytesRead: number, buffer: +Buffer))", + "!type": "fn(fd: number, buffer: string|+Buffer, offset: number, length: number, position: number, callback: fn(err: +Error, bytesRead: number, buffer: +Buffer))", "!url": "https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback", "!doc": "Read data from the file specified by fd." }, readdir: { - "!type": "fn(path: string, callback?: fn(err: +Error, files: [string]))", - "!url": "https://nodejs.org/api/fs.html#fs_fs_readdir_path_callback", + "!type": "fn(path: string|+Buffer, options?: ?, callback: fn(err: +Error, files: [string|+Buffer]))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_readdir_path_options_callback", "!doc": "Asynchronous readdir(3). Reads the contents of a directory. The callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'." }, readdirSync: { - "!type": "fn(path: string) -> [string]", - "!url": "https://nodejs.org/api/fs.html#fs_fs_readdirsync_path", + "!type": "fn(path: string|+Buffer, options?: ?) -> [string|+Buffer]", + "!url": "https://nodejs.org/api/fs.html#fs_fs_readdirsync_path_options", "!doc": "Synchronous readdir(3). Returns an array of filenames excluding '.' and '..'." }, readFile: { - "!type": "fn(filename: string, callback: fn(err: +Error, data: +Buffer))", - "!url": "https://nodejs.org/api/fs.html#fs_fs_readfile_filename_options_callback", - "!doc": "Asynchronously reads the entire contents of a file." + "!type": "fn(file: string|+Buffer|number, options?: ?, callback: fn(err: +Error, data: string|+Buffer))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_readfile_file_options_callback", + "!doc": "Asynchronously reads the entire contents of a file. Example:" }, readFileSync: { - "!type": "fn(filename: string, encoding: string) -> +Buffer", - "!url": "https://nodejs.org/api/fs.html#fs_fs_readfilesync_filename_options", - "!doc": "Synchronous version of fs.readFile. Returns the contents of the filename." + "!type": "fn(file: string|+Buffer|number, options?: ?) -> string|+Buffer", + "!url": "https://nodejs.org/api/fs.html#fs_fs_readfilesync_file_options", + "!doc": "Synchronous version of fs.readFile. Returns the contents of the file." }, readlink: { - "!type": "fn(path: string, callback?: fn(err: +Error, linkString: string))", - "!url": "https://nodejs.org/api/fs.html#fs_fs_readlink_path_callback", + "!type": "fn(path: string|+Buffer, options?: ?, callback: fn(err: +Error, linkString: string|+Buffer))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_readlink_path_options_callback", "!doc": "Asynchronous readlink(2). The callback gets two arguments (err, linkString)." }, readlinkSync: { - "!type": "fn(path: string)", - "!url": "https://nodejs.org/api/fs.html#fs_fs_readlinksync_path", + "!type": "fn(path: string|+Buffer, options?: ?) -> string|+Buffer", + "!url": "https://nodejs.org/api/fs.html#fs_fs_readlinksync_path_options", "!doc": "Synchronous readlink(2). Returns the symbolic link's string value." }, readSync: { - "!type": "fn(fd: number, buffer: +Buffer, offset: number, length: number, position: number) -> number", + "!type": "fn(fd: number, buffer: string|+Buffer, offset: number, length: number, position: number) -> number", "!url": "https://nodejs.org/api/fs.html#fs_fs_readsync_fd_buffer_offset_length_position", - "!doc": "Synchronous version of fs.read. Returns the number of bytesRead." + "!doc": "Synchronous version of fs.read(). Returns the number of bytesRead." }, realpath: { - "!type": "fn(path: string, cache: bool, callback: fn(err: +Error, resolvedPath: string))", - "!url": "https://nodejs.org/api/fs.html#fs_fs_realpath_path_cache_callback", - "!doc": "Asynchronous realpath(2). The callback gets two arguments (err, resolvedPath). May use process.cwd to resolve relative paths. cache is an object literal of mapped paths that can be used to force a specific path resolution or avoid additional fs.stat calls for known real paths." + "!type": "fn(path: string|+Buffer, options?: ?, callback: fn(err: +Error, resolvedPath: string|+Buffer))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_realpath_path_options_callback", + "!doc": "Asynchronous realpath(3). The callback gets two arguments (err, resolvedPath). May use process.cwd to resolve relative paths." }, realpathSync: { - "!type": "fn(path: string, cache?: bool) -> string", - "!url": "https://nodejs.org/api/fs.html#fs_fs_realpathsync_path_cache", - "!doc": "Synchronous realpath(2). Returns the resolved path." + "!type": "fn(path: string|+Buffer, options?: ?) -> string|+Buffer", + "!url": "https://nodejs.org/api/fs.html#fs_fs_realpathsync_path_options", + "!doc": "Synchronous realpath(3). Returns the resolved path." }, rename: { - "!type": "fn(oldPath: string, newPath: string, callback?: fn())", + "!type": "fn(oldPath: string|+Buffer, newPath: string|+Buffer, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback", "!doc": "Asynchronous rename(2). No arguments other than a possible exception are given to the completion callback." }, renameSync: { - "!type": "fn(oldPath: string, newPath: string)", + "!type": "fn(oldPath: string|+Buffer, newPath: string|+Buffer)", "!url": "https://nodejs.org/api/fs.html#fs_fs_renamesync_oldpath_newpath", - "!doc": "Synchronous rename(2)." + "!doc": "Synchronous rename(2). Returns undefined." }, rmdir: { - "!type": "fn(path: string, callback?: fn())", + "!type": "fn(path: string|+Buffer, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_rmdir_path_callback", "!doc": "Asynchronous rmdir(2). No arguments other than a possible exception are given to the completion callback." }, rmdirSync: { - "!type": "fn(path: string)", + "!type": "fn(path: string|+Buffer)", "!url": "https://nodejs.org/api/fs.html#fs_fs_rmdirsync_path", - "!doc": "Synchronous rmdir(2)." + "!doc": "Synchronous rmdir(2). Returns undefined." }, stat: { - "!type": "fn(path: string, callback?: fn(err: +Error, stats: +fs.Stats) -> ?) -> +fs.Stats", + "!type": "fn(path: string|+Buffer, callback: fn(err: +Error, stats: +fs.Stats))", "!url": "https://nodejs.org/api/fs.html#fs_fs_stat_path_callback", - "!doc": "Asynchronous stat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object." + "!doc": "Asynchronous stat(2). The callback gets two arguments (err, stats) where stats is a fs.Stats object. See the fs.Stats section for more information." }, statSync: { - "!type": "fn(path: string) -> +fs.Stats", + "!type": "fn(path: string|+Buffer) -> +fs.Stats", "!url": "https://nodejs.org/api/fs.html#fs_fs_statsync_path", "!doc": "Synchronous stat(2). Returns an instance of fs.Stats." }, symlink: { - "!type": "fn(srcpath: string, dstpath: string, type?: string, callback?: fn())", - "!url": "https://nodejs.org/api/fs.html#fs_fs_symlink_srcpath_dstpath_type_callback", - "!doc": "Asynchronous symlink(2). No arguments other than a possible exception are given to the completion callback. type argument can be either 'dir', 'file', or 'junction' (default is 'file'). It is only used on Windows (ignored on other platforms). Note that Windows junction points require the destination path to be absolute. When using 'junction', the destination argument will automatically be normalized to absolute path." + "!type": "fn(target: string|+Buffer, path: string|+Buffer, type?: string, callback: fn(err: +Error))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_symlink_target_path_type_callback", + "!doc": "Asynchronous symlink(2). No arguments other than a possible exception are given to the completion callback. The type argument can be set to 'dir', 'file', or 'junction' (default is 'file') and is only available on Windows (ignored on other platforms). Note that Windows junction points require the destination path to be absolute. When using 'junction', the target argument will automatically be normalized to absolute path." }, symlinkSync: { - "!type": "fn(srcpath: string, dstpath: string, type?: string)", - "!url": "https://nodejs.org/api/fs.html#fs_fs_symlinksync_srcpath_dstpath_type", - "!doc": "Synchronous symlink(2)." + "!type": "fn(target: string|+Buffer, path: string|+Buffer, type?: string)", + "!url": "https://nodejs.org/api/fs.html#fs_fs_symlinksync_target_path_type", + "!doc": "Synchronous symlink(2). Returns undefined." }, truncate: { - "!type": "fn(path: string, len: number, callback?: fn())", + "!type": "fn(path: string|+Buffer, len: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_truncate_path_len_callback", - "!doc": "Asynchronous truncate(2). No arguments other than a possible exception are given to the completion callback." + "!doc": "Asynchronous truncate(2). No arguments other than a possible exception are given to the completion callback. A file descriptor can also be passed as the first argument. In this case, fs.ftruncate() is called." }, truncateSync: { - "!type": "fn(path: string, len: number)", + "!type": "fn(path: string|+Buffer, len: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_truncatesync_path_len", - "!doc": "Synchronous truncate(2)." + "!doc": "Synchronous truncate(2). Returns undefined. A file descriptor can also be passed as the first argument. In this case, fs.ftruncateSync() is called." }, unlink: { - "!type": "fn(path: string, callback?: fn())", + "!type": "fn(path: string|+Buffer, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_unlink_path_callback", "!doc": "Asynchronous unlink(2). No arguments other than a possible exception are given to the completion callback." }, unlinkSync: { - "!type": "fn(path: string)", + "!type": "fn(path: string|+Buffer)", "!url": "https://nodejs.org/api/fs.html#fs_fs_unlinksync_path", - "!doc": "Synchronous unlink(2)." + "!doc": "Synchronous unlink(2). Returns undefined." }, unwatchFile: { - "!type": "fn(filename: string, listener?: fn())", + "!type": "fn(filename: string|+Buffer, listener?: fn(curr: +fs.Stats, prev: +fs.Stats))", "!url": "https://nodejs.org/api/fs.html#fs_fs_unwatchfile_filename_listener", "!doc": "Stop watching for changes on filename. If listener is specified, only that particular listener is removed. Otherwise, all listeners are removed and you have effectively stopped watching filename." }, utimes: { - "!type": "fn(path: string, atime: number, mtime: number, callback?: fn())", + "!type": "fn(path: string|+Buffer, atime: number, mtime: number, callback: fn(err: +Error))", "!url": "https://nodejs.org/api/fs.html#fs_fs_utimes_path_atime_mtime_callback", "!doc": "Change file timestamps of the file referenced by the supplied path." }, utimesSync: { - "!type": "fn(path: string, atime: number, mtime: number)", + "!type": "fn(path: string|+Buffer, atime: number, mtime: number)", "!url": "https://nodejs.org/api/fs.html#fs_fs_utimessync_path_atime_mtime", - "!doc": "Change file timestamps of the file referenced by the supplied path." + "!doc": "Synchronous version of fs.utimes(). Returns undefined." }, watch: { - "!type": "fn(filename: string, options?: ?, listener?: fn(event: string, filename: string)) -> +fs.FSWatcher", + "!type": "fn(filename: string|+Buffer, options?: ?, listener?: fn(eventType: string, filename?: string)) -> +fs.FSWatcher", "!url": "https://nodejs.org/api/fs.html#fs_fs_watch_filename_options_listener", "!doc": "Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher." }, watchFile: { - "!type": "fn(filename: string, options: ?, listener: fn(current: +fs.Stats, prev: +fs.Stats))", + "!type": "fn(filename: string|+Buffer, options?: ?, listener: fn(curr: +fs.Stats, prev: +fs.Stats))", "!url": "https://nodejs.org/api/fs.html#fs_fs_watchfile_filename_options_listener", "!doc": "Watch for changes on filename. The callback listener will be called each time the file is accessed." }, write: { - "!type": "fn(fd: number, buffer: +Buffer, offset: number, length: number, position: number, callback?: fn(err: +Error, written: number, buffer: +Buffer))", - "!url": "https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback", - "!doc": "Write buffer to the file specified by fd." + "!type": "fn(fd: number, data: string|+Buffer, position?: number, encoding?: string, callback: fn(err: +Error, bytesRead: number, buffer: +Buffer))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_write_fd_data_position_encoding_callback", + "!doc": "Write data to the file specified by fd. If data is not a Buffer instance then the value will be coerced to a string." }, writeFile: { - "!type": "fn(filename: string, data: string|+Buffer, encoding?: string, callback?: fn())", - "!url": "https://nodejs.org/api/fs.html#fs_fs_writefile_filename_data_options_callback", + "!type": "fn(file: string|+Buffer|number, data: string|+Buffer, options?: ?, callback: fn(err: +Error))", + "!url": "https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback", "!doc": "Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer." }, writeFileSync: { - "!type": "fn(filename: string, data: string|+Buffer, encoding?: string)", - "!url": "https://nodejs.org/api/fs.html#fs_fs_writefilesync_filename_data_options", - "!doc": "The synchronous version of fs.writeFile." + "!type": "fn(file: string|+Buffer|number, data: string|+Buffer, options?: ?)", + "!url": "https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options", + "!doc": "The synchronous version of fs.writeFile(). Returns undefined." }, writeSync: { - "!type": "fn(fd: number, buffer: +Buffer, offset: number, length: number, position: number) -> number", - "!url": "https://nodejs.org/api/fs.html#fs_fs_writesync_fd_buffer_offset_length_position", - "!doc": "Synchronous version of fs.write(). Returns the number of bytes written." + "!type": "fn(fd: number, data: string|+Buffer, position?: number, encoding?: string) -> number", + "!url": "https://nodejs.org/api/fs.html#fs_fs_writesync_fd_data_position_encoding", + "!doc": "Synchronous versions of fs.write(). Returns the number of bytes written." }, FSWatcher: { "!type": "fn()", "!url": "https://nodejs.org/api/fs.html#fs_class_fs_fswatcher", "!doc": "Objects returned from fs.watch() are of this type.", prototype: { - close: "fn()" + close: { + "!type": "fn()", + "!url": "https://nodejs.org/api/fs.html#fs_watcher_close", + "!doc": "Stop watching for changes on the given fs.FSWatcher." + } + } + }, + ReadStream: { + "!type": "fn()", + "!url": "https://nodejs.org/api/fs.html#fs_class_fs_readstream", + "!doc": "ReadStream is a Readable Stream.", + prototype: { + bytesRead: { + "!type": "number", + "!url": "https://nodejs.org/api/fs.html#fs_readstream_bytesread", + "!doc": "The number of bytes read so far." + }, + path: { + "!type": "string", + "!url": "https://nodejs.org/api/fs.html#fs_readstream_path", + "!doc": "The path to the file the stream is reading from as specified in the first argument to fs.createReadStream(). If path is passed as a string, then readStream.path will be a string. If path is passed as a Buffer, then readStream.path will be a Buffer." + }, + "!proto": "stream.Readable" } }, Stats: { @@ -1681,8 +1733,70 @@ blocks: "number", atime: "+Date", mtime: "+Date", - ctime: "+Date" + ctime: "+Date", + birthtime: "+Date" } + }, + WriteStream: { + "!type": "fn()", + "!url": "https://nodejs.org/api/fs.html#fs_class_fs_writestream", + "!doc": "WriteStream is a Writable Stream.", + prototype: { + bytesWritten: { + "!type": "number", + "!url": "https://nodejs.org/api/fs.html#fs_writestream_byteswritten", + "!doc": "The number of bytes written so far. Does not include data that is still queued for writing." + }, + path: { + "!type": "string", + "!url": "https://nodejs.org/api/fs.html#fs_writestream_path", + "!doc": "The path to the file the stream is writing to as specified in the first argument to fs.createWriteStream(). If path is passed as a string, then writeStream.path will be a string. If path is passed as a Buffer, then writeStream.path will be a Buffer." + }, + "!proto": "stream.Writable" + } + }, + constants: { + "!url": "https://nodejs.org/api/fs.html#fs_fs_constants", + "!doc": "Returns an object containing commonly used constants for file system operations. The specific constants currently defined are described in FS Constants.", + F_OK: "number", + R_OK: "number", + W_OK: "number", + X_OK: "number", + O_RDONLY: "number", + O_WRONLY: "number", + O_RDWR: "number", + O_CREAT: "number", + O_EXCL: "number", + O_NOCTTY: "number", + O_TRUNC: "number", + O_APPEND: "number", + O_DIRECTORY: "number", + O_NOATIME: "number", + O_NOFOLLOW: "number", + O_SYNC: "number", + O_SYMLINK: "number", + O_DIRECT: "number", + O_NONBLOCK: "number", + S_IFMT: "number", + S_IFREG: "number", + S_IFDIR: "number", + S_IFCHR: "number", + S_IFBLK: "number", + S_IFIFO: "number", + S_IFLNK: "number", + S_IFSOCK: "number", + S_IRWXU: "number", + S_IRUSR: "number", + S_IWUSR: "number", + S_IXUSR: "number", + S_IRWXG: "number", + S_IRGRP: "number", + S_IWGRP: "number", + S_IXGRP: "number", + S_IRWXO: "number", + S_IROTH: "number", + S_IWOTH: "number", + S_IXOTH: "number" } }, path: { diff --git a/test/cases/node/main.js b/test/cases/node/main.js index ef9e1e93..60aa70fd 100644 --- a/test/cases/node/main.js +++ b/test/cases/node/main.js @@ -2,7 +2,7 @@ var fs = require("fs"), crypto = require("crypto"), tls = require("tls"); -fs.readFileSync; //: fn(filename: string, encoding: string) -> Buffer +fs.createReadStream; //: fn(path: string|Buffer, options?: ?) -> fs.ReadStream fs.stat("foobar", function(err, stats) { err; //: Error