# HG changeset patch # User Yaroslav Zhuravlev # Date 1661889658 -3600 # Node ID 155c8745f596450a12a3c63eed640e92446b3fc4 # Parent 76fddfe7826d4b00c93b3d53046e84007dffc9c8 Documented new fs methods and fs.FileHandle in njs Reference. diff --git a/xml/en/docs/njs/reference.xml b/xml/en/docs/njs/reference.xml --- a/xml/en/docs/njs/reference.xml +++ b/xml/en/docs/njs/reference.xml @@ -9,7 +9,7 @@
+ rev="88">
@@ -3462,9 +3462,9 @@ otherwise, the method will return undefi mode -by default is fs.constants.F_OK. -The mode argument is an optional integer -that specifies the accessibility checks to be performed. +an optional integer +that specifies the accessibility checks to be performed, +by default is fs.constants.F_OK try { fs.accessSync('/file/path', fs.constants.R_OK | fs.constants.W_OK); @@ -3504,6 +3504,15 @@ by default is a +fstatSync(fd) + +Retrieves the fs.Stats object +for the file descriptor +(0.7.7). +The fd parameter is an integer +representing the file descriptor used by the method. + + lstatSync(path[, options]) @@ -3543,6 +3552,97 @@ mode option, by default is 0o77 +openSync(path[, +flags[, mode]]) + +Returns an integer +representing the file descriptor for the opened file path +(0.7.7). + + +flags + +file system flag, +by default is r + + +mode + +mode option, by default is 0o666 + + + + + +promises.open(path[, +flags[, mode]]) + +Returns a FileHandle object +representing the opened file path +(0.7.7). + + +flags + +file system flag, +by default is r + + +mode + +mode option, by default is 0o666 + + + + + +readSync(fd, +buffer, offset[, +length[, position]]) + +Reads the content of a file path using file descriptor fd, +returns the number of bytes read +(0.7.7). + + + +buffer + +the buffer value can be a +Buffer, +TypedArray, or +DataView + + +offset + +is an integer representing +the position in buffer to write the data to + + +length + +is an integer representing +the number of bytes to read + + +position + +specifies where to begin reading from in the file, +the value can be +integer or +null, +by default is null. +If position is null, +data will be read from the current file position, +and the file position will be updated. +If position is an integer, +the file position will be unchanged + + + + + readdirSync(path[, options]) @@ -3684,6 +3784,95 @@ pointing to target us Relative targets are relative to the link’s parent directory. +writeSync(fd, +buffer, offset[, +length[, position]]) + +Writes a buffer to a file using file descriptor, +returns the number of bytes written +(0.7.7). + + + +fd + +an integer representing the file descriptor + + +buffer + +the buffer value can be a +Buffer, +TypedArray, or +DataView + + +offset + +is an integer that determines +the part of the buffer to be written, +by default 0 + + +length + +is an integer specifying the number of bytes to write, +by default is an offset of +Buffer.byteLength + + +position + +refers to the offset from the beginning of the file +where this data should be written, +can be an +integer or +null, +by default is null. +See also +pwrite(2). + + + + + +writeSync(fd, +string[, +position[, +encoding]]) + +Writes a string to a file +using file descriptor fd, +returns the number of bytes written +(0.7.7). + + + +fd + +is an integer representing a file descriptor + + +position + +refers to the offset from the beginning of the file +where this data should be written, +can be an +integer or +null, by default is null. +See also +pwrite(2) + + +encoding + +is a string, +by default is utf8 + + + + + unlinkSync(path) Synchronously unlinks a file by path @@ -3794,6 +3983,241 @@ the name of the file fs.Dirent<
+
+ + +The FileHandle object is an object wrapper +for a numeric file descriptor +(0.7.7). +Instances of the FileHandle object are created by the +fs.promises.open() method. +If a FileHandle is not closed using the +filehandle.close() method, +it will try to automatically close the file descriptor, +helping to prevent memory leaks. +Please do not rely on this behavior because it can be unreliable. +Instead, always explicitly close a FileHandle. + + + + + +filehandle.close() + +Closes the file handle after waiting for any pending operation on the handle +to complete. +Returns a promise, fulfills with undefined upon success. + + +filehandle.fd + +The numeric file descriptor +managed by the FileHandle object. + + +filehandle.read(buffer, +offset[, +length[, +position]]) + +Reads data from the file and stores that in the given buffer. + + + +buffer + +a buffer that will be filled with the file data read, +the value can be a +Buffer, +TypedArray, or +DataView + + +offset + +is an integer +representing the location in the buffer at which to start filling + + +length + +is an integer +representing the number of bytes to read + + +position + +the location where to begin reading data from the file, +the value can be +integer, +null. +If null, data will be read from the current file position +and the position will be updated. +If position is an integer, +the current file position will remain unchanged. + + + +Returns a Promise which fulfills upon success +with an object with two properties: + + +bytesRead + +is an integer representing the number of bytes read + + +buffer + +is a reference to the passed argument in buffer, can be +Buffer, +TypedArray, or +DataView + + + + + +filehandle.stat() + +Fulfills with an +fs.Stats for the file, +returns a promise. + + +filehandle.write(buffer, +offset[, +length[, +position]]) + +Writes a buffer to the file. + + + +buffer + +the buffer value can be a +Buffer, +TypedArray, or +DataView + + +offset + +is an integer representing +the start position from within buffer where the data to write begins + + +length + +is an integer representing +the number of bytes from buffer to write, by default +is an offset of +Buffer.byteLength + + +position + +the offset from the beginning of the file +where the data from buffer should be written, +can be an +integer or +null, +by default is null. +If position is not a number, +the data will be written at the current position. +See the POSIX +pwrite(2) +documentation for details. + + +Returns a Promise which is resolved with an object +containing two properties: + + +bytesWritten + +is an integer representing the number of bytes written + + +buffer + +a reference to the buffer written, can be a +Buffer, +TypedArray, or +DataView + + + + +It is unsafe to use filehandle.write() multiple times +on the same file without waiting for the promise to be resolved or rejected. + + + + + +filehandle.write(string[, +position[, +encoding]]) + +Writes a string to the file. + + + +position + +the offset from the beginning of the file +where the data from buffer should be written, +can be an +integer or +null, +by default is null. +If position is not a number, +the data will be written at the current position. +See the POSIX +pwrite(2) +documentation for details. + + +encoding + +the expected encoding of the string, by default utf8 + + + +Returns a Promise which is resolved with an object +containing two properties: + + +bytesWritten + +is an integer representing the number of bytes written + + +buffer + +a reference to the buffer written, can be a +Buffer, +TypedArray, or +DataView + + + + +It is unsafe to use filehandle.write() multiple times +on the same file without waiting for the promise to be resolved or rejected. + + + + + + + + +
+ +