trait Fs extends Object with IEventEmitter with FSConstants
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.
The asynchronous form always takes a completion callback as its last argument. The arguments passed to the completion callback depend on the method, but the first argument is always reserved for an exception. If the operation was completed successfully, then the first argument will be null or undefined.
When using the synchronous form any exceptions are immediately thrown. You can use try/catch to handle exceptions or allow them to bubble up.
- Annotations
- @RawJSType() @native()
- Alphabetic
- By Inheritance
- Fs
- FSConstants
- IEventEmitter
- Object
- Any
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##(): Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val COPYFILE_EXCL: Int
- Definition Classes
- FSConstants
- val F_OK: FileMode
File is visible to the calling process.
File is visible to the calling process. This is useful for determining if a file exists, but says nothing about rwx permissions. Default if no mode is specified.
- Definition Classes
- FSConstants
- val O_APPEND: Int
Flag indicating that data will be appended to the end of the file.
Flag indicating that data will be appended to the end of the file.
- Definition Classes
- FSConstants
- val O_CREAT: Int
Flag indicating to create the file if it does not already exist.
Flag indicating to create the file if it does not already exist.
- Definition Classes
- FSConstants
- val O_DIRECT: Int
When set, an attempt will be made to minimize caching effects of file I/O.
When set, an attempt will be made to minimize caching effects of file I/O.
- Definition Classes
- FSConstants
- val O_DIRECTORY: Int
Flag indicating that the open should fail if the path is not a directory.
Flag indicating that the open should fail if the path is not a directory.
- Definition Classes
- FSConstants
- val O_DSYNC: Int
Flag indicating that the file is opened for synchronized I/O with write operations waiting for data integrity.
Flag indicating that the file is opened for synchronized I/O with write operations waiting for data integrity.
- Definition Classes
- FSConstants
- val O_EXCL: Int
Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists.
Flag indicating that opening a file should fail if the O_CREAT flag is set and the file already exists.
- Definition Classes
- FSConstants
- val O_NOATIME: Int
Flag indicating reading accesses to the file system will no longer result in an update to the atime information associated with the file.
Flag indicating reading accesses to the file system will no longer result in an update to the atime information associated with the file. This flag is available on Linux operating systems only.
- Definition Classes
- FSConstants
- val O_NOCTTY: Int
Flag indicating that if path identifies a terminal device, opening the path shall not cause that terminal to become the controlling terminal for the process (if the process does not already have one).
Flag indicating that if path identifies a terminal device, opening the path shall not cause that terminal to become the controlling terminal for the process (if the process does not already have one).
- Definition Classes
- FSConstants
- val O_NOFOLLOW: Int
Flag indicating that the open should fail if the path is a symbolic link.
Flag indicating that the open should fail if the path is a symbolic link.
- Definition Classes
- FSConstants
- val O_NONBLOCK: Int
Flag indicating to open the file in nonblocking mode when possible.
Flag indicating to open the file in nonblocking mode when possible.
- Definition Classes
- FSConstants
- val O_RDONLY: Int
Flag indicating to open a file for read-only access.
Flag indicating to open a file for read-only access.
- Definition Classes
- FSConstants
- val O_RDWR: Int
Flag indicating to open a file for read-write access.
Flag indicating to open a file for read-write access.
- Definition Classes
- FSConstants
- val O_SYMLINK: Int
Flag indicating to open the symbolic link itself rather than the resource it is pointing to.
Flag indicating to open the symbolic link itself rather than the resource it is pointing to.
- Definition Classes
- FSConstants
- val O_SYNC: Int
Flag indicating that the file is opened for synchronous I/O.
Flag indicating that the file is opened for synchronous I/O.
- Definition Classes
- FSConstants
- val O_TRUNC: Int
Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero.
Flag indicating that if the file exists and is a regular file, and the file is opened successfully for write access, its length shall be truncated to zero.
- Definition Classes
- FSConstants
- val O_WRONLY: Int
Flag indicating to open a file for write-only access.
Flag indicating to open a file for write-only access.
- Definition Classes
- FSConstants
- val R_OK: FileMode
File can be read by the calling process.
File can be read by the calling process.
- Definition Classes
- FSConstants
- val S_IFBLK: FileType
File type constant for a block-oriented device file.
File type constant for a block-oriented device file.
- Definition Classes
- FSConstants
- val S_IFCHR: FileType
File type constant for a character-oriented device file.
File type constant for a character-oriented device file.
- Definition Classes
- FSConstants
- val S_IFDIR: FileType
File type constant for a directory.
File type constant for a directory.
- Definition Classes
- FSConstants
- val S_IFIFO: FileType
File type constant for a FIFO/pipe.
File type constant for a FIFO/pipe.
- Definition Classes
- FSConstants
- val S_IFLNK: FileType
File type constant for a symbolic link.
File type constant for a symbolic link.
- Definition Classes
- FSConstants
- val S_IFMT: FileType
Bit mask used to extract the file type code.
Bit mask used to extract the file type code.
- Definition Classes
- FSConstants
- val S_IFREG: FileType
File type constant for a regular file.
File type constant for a regular file.
- Definition Classes
- FSConstants
- val S_IFSOCK: FileType
File type constant for a socket.
File type constant for a socket.
- Definition Classes
- FSConstants
- val S_IRGRP: FileMode
- Definition Classes
- FSConstants
- val S_IROTH: FileMode
- Definition Classes
- FSConstants
- val S_IRUSR: FileMode
- Definition Classes
- FSConstants
- val S_IRWXG: FileMode
- Definition Classes
- FSConstants
- val S_IRWXO: FileMode
- Definition Classes
- FSConstants
- val S_IRWXU: FileMode
- Definition Classes
- FSConstants
- val S_IWGRP: FileMode
- Definition Classes
- FSConstants
- val S_IWOTH: FileMode
- Definition Classes
- FSConstants
- val S_IWUSR: FileMode
- Definition Classes
- FSConstants
- val S_IXGRP: FileMode
- Definition Classes
- FSConstants
- val S_IXOTH: FileMode
- Definition Classes
- FSConstants
- val S_IXUSR: FileMode
- Definition Classes
- FSConstants
- val W_OK: FileMode
File can be written by the calling process.
File can be written by the calling process.
- Definition Classes
- FSConstants
- val X_OK: FileMode
File can be executed by the calling process.
File can be executed by the calling process. This has no effect on Windows (will behave like F_OK).
- Definition Classes
- FSConstants
- def access(path: Path, callback: FsCallback0): Unit
Tests a user's permissions for the file specified by path.
Tests a user's permissions for the file specified by path. mode 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.
- fs.F_OK - File is visible to the calling process. This is useful for determining if a file exists, but says nothing about rwx permissions. Default if no mode is specified.
- FSConstants.R_OK - File can be read by the calling process.
- FSConstants.W_OK - File can be written by the calling process.
- FSConstants.X_OK - File can be executed by the calling process. This has no effect on Windows (will behave like F_OK).
- path
the path (Buffer | String)
- callback
is a callback function that is invoked with a possible error argument. If any of the accessibility checks fail, the error argument will be populated.
fs.access(path[, mode], callback)
Example: - def access(path: Path, mode: FileMode, callback: FsCallback0): Unit
Tests a user's permissions for the file specified by path.
Tests a user's permissions for the file specified by path. mode 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.
- fs.F_OK - File is visible to the calling process. This is useful for determining if a file exists, but says nothing about rwx permissions. Default if no mode is specified.
- FSConstants.R_OK - File can be read by the calling process.
- FSConstants.W_OK - File can be written by the calling process.
- FSConstants.X_OK - File can be executed by the calling process. This has no effect on Windows (will behave like F_OK).
- path
the path (Buffer | String)
- mode
the optional mode
- callback
is a callback function that is invoked with a possible error argument. If any of the accessibility checks fail, the error argument will be populated.
fs.access(path[, mode], callback)
Example: - def accessSync(path: Path, mode: FileMode = js.native): Unit
Synchronous version of fs.access().
Synchronous version of fs.access(). This throws if any accessibility checks fail, and does nothing otherwise.
- path
the path (Buffer | String)
- mode
the optional mode
fs.accessSync(path[, mode])
Example: - def addListener(eventName: String, listener: Function): Fs.this.type
Alias for emitter.on(eventName, listener).
Alias for emitter.on(eventName, listener).
- Definition Classes
- IEventEmitter
emitter.addListener(eventName, listener)
- See also
on()
Example: - def appendFile(path: |[Path, FileDescriptor], data: |[Buffer, String], callback: FsCallback0): Unit
Asynchronously append data to a file, creating the file if it does not yet exist.
Asynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a buffer.
- path
the filename or file descriptor (Buffer | String | Number)
- data
the data to append (Buffer | String)
- callback
the callback function
fs.appendFile(file, data[, options], callback)
Example: - def appendFile(file: |[Path, FileDescriptor], data: |[Buffer, String], options: FileAppendOptions, callback: FsCallback0): Unit
Asynchronously append data to a file, creating the file if it does not yet exist.
Asynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a buffer.
- file
the filename or file descriptor (Buffer | String | Number)
- data
the data to append (Buffer | String)
- options
- callback
the callback function
fs.appendFile(file, data[, options], callback)
Example: - def appendFileSync(path: |[Path, FileDescriptor], data: |[Buffer, String], options: FileAppendOptions = js.native): Unit
The synchronous version of fs.appendFile().
The synchronous version of fs.appendFile().
- path
the filename or file descriptor (Buffer | String | Number)
- data
the data to append (Buffer | String)
- options
- returns
undefined.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def chmod(path: Path, mode: FileMode, callback: FsCallback0): Unit
Asynchronous chmod(2).
Asynchronous chmod(2). No arguments other than a possible exception are given to the completion callback.
- path
the file or directory path (Buffer | String)
- mode
the file or directory mode
- callback
the completion callback.
- def chmodSync(path: Path, mode: FileMode): Unit
Synchronous chmod(2).
Synchronous chmod(2).
- path
the file or directory path (Buffer | String)
- mode
the file or directory mode
- returns
undefined.
- def chown(path: Path, uid: UID, gid: GID, callback: FsCallback0): Unit
Asynchronous chown(2).
Asynchronous chown(2). No arguments other than a possible exception are given to the completion callback.
- path
the file or directory path (Buffer | String)
- uid
the user ID
- gid
the group ID
- callback
the completion callback.
- def chownSync(path: Path, uid: UID, gid: GID): Unit
Synchronous chown(2).
Synchronous chown(2).
- path
the file or directory path (Buffer | String)
- uid
the user ID
- gid
the group ID
- returns
undefined.
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def close(fd: FileDescriptor, callback: FsCallback0): Unit
Asynchronous close(2).
Asynchronous close(2). No arguments other than a possible exception are given to the completion callback.
fs.close(fd, callback)
Example: - def closeSync(fd: FileDescriptor): Unit
Synchronous close(2).
Synchronous close(2).
- returns
undefined.
fs.closeSync(fd)
Example: - def constants: FSConstants
Returns an object containing commonly used constants for file system operations
Returns an object containing commonly used constants for file system operations
- returns
an object containing commonly used constants for file system operations
- def copyFile(src: Path, dest: Path, callback: FsCallback0): Unit
Asynchronously copies src to dest.
Asynchronously copies src to dest. By default, dest is overwritten if it already exists. No arguments other than a possible exception are given to the callback function. Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.
flags is an optional integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
- src
the source filename to copy
- dest
the destination filename of the copy operation
- callback
the callback function
fs.copyFile(src, dest[, flags], callback)
Example: - def copyFile(src: Path, dest: Path, flags: Flags, callback: FsCallback0): Unit
Asynchronously copies src to dest.
Asynchronously copies src to dest. By default, dest is overwritten if it already exists. No arguments other than a possible exception are given to the callback function. Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.
flags is an optional integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
- src
the source filename to copy
- dest
the destination filename of the copy operation
- flags
the modifiers for copy operation. Default: 0
- callback
the callback function
fs.copyFile(src, dest[, flags], callback)
Example: - def copyFileSync(src: Path, dest: Path, flags: Flags): Unit
Synchronously copies src to dest.
Synchronously copies src to dest. By default, dest is overwritten if it already exists.
Node.js makes no guarantees about the atomicity of the copy operation. If an error occurs after the destination file has been opened for writing, Node.js will attempt to remove the destination.
flags is an optional integer that specifies the behavior of the copy operation. The only supported flag is fs.constants.COPYFILE_EXCL, which causes the copy operation to fail if dest already exists.
- src
the source filename to copy
- dest
the destination filename of the copy operation
- flags
the modifiers for copy operation. Default: 0
fs.copyFileSync(src, dest[, flags])
Example: - def createReadStream(path: Path, options: FileInputOptions = js.native): ReadStream
Returns a new ReadStream object.
Returns a new ReadStream object. (See Readable Stream). Be aware that, unlike the default value set for highWaterMark on a readable stream (16 kb), the stream returned by this method has a default value of 64 kb for the same parameter.
- path
the path (Buffer | String)
- options
the optional stream options
fs.createReadStream(path[, options])
Example: - def createWriteStream(path: Path, options: FileOutputOptions = js.native): WriteStream
Returns a new WriteStream object.
Returns a new WriteStream object.
- path
the path (Buffer | String)
- options
the optional stream options
fs.createWriteStream(path[, options])
Example: - val domain: String
- Definition Classes
- IEventEmitter
- def emit(name: String, args: Any*): Boolean
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.
Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.
Returns true if the event had listeners, false otherwise.
- name
the event name
- args
the event arguments
- Definition Classes
- IEventEmitter
emitter.emit(name[, arg1][, arg2][, ...])
Example: - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def eventNames(): Array[String]
- Definition Classes
- IEventEmitter
- def existsSync(path: Path): Boolean
fs.exists() should not be used to check if a file exists before calling fs.open().
fs.exists() should not be used to check if a file exists before calling fs.open(). Doing so introduces a race condition since other processes may change the file's state between the two calls. Instead, user code should call fs.open() directly and handle the error raised if the file is non-existent.
fs.existsSync(path)
Example: - def fchmod(fd: FileDescriptor, mode: FileMode, callback: FsCallback0): Unit
Asynchronous fchmod(2).
Asynchronous fchmod(2). No arguments other than a possible exception are given to the completion callback.
fs.fchmod(fd, mode, callback)
Example: - def fchmodSync(fd: FileDescriptor, mode: FileMode): Unit
Synchronous fchmod(2).
Synchronous fchmod(2).
- returns
undefined.
fs.fchmodSync(fd, mode)
Example: - def fchown(fd: FileDescriptor, uid: UID, gid: GID, callback: FsCallback0): Unit
Asynchronous fchown(2).
Asynchronous fchown(2). No arguments other than a possible exception are given to the completion callback.
- fd
the file descriptor
- uid
the user ID
- gid
the group ID
- callback
the completion callback.
- def fchownSync(fd: FileDescriptor, uid: UID, gid: GID): Unit
Synchronous fchown(2).
Synchronous fchown(2).
- fd
the file descriptor
- uid
the user ID
- gid
the group ID
- def fdatasync(fd: FileDescriptor, callback: FsCallback0): Unit
Asynchronous fdatasync(2).
Asynchronous fdatasync(2). No arguments other than a possible exception are given to the completion callback.
fs.fdatasync(fd, callback)
Example: - def fdatasyncSync(fd: FileDescriptor): Unit
Synchronous fdatasync(2).
Synchronous fdatasync(2).
- returns
undefined.
fs.fdatasyncSync(fd)
Example: - def fstat(fd: FileDescriptor, options: StatOptions, callback: FsCallback1[Stats]): Unit
- def fstat(fd: FileDescriptor, callback: FsCallback1[Stats]): Unit
Asynchronous fstat(2).
Asynchronous fstat(2). The callback gets two arguments (err, stats) where stats is an fs.Stats object. fstat() is identical to stat(), except that the file to be stat-ed is specified by the file descriptor fd.
- fd
the file descriptor
- callback
the completion callback.
- def fstatSync(fd: FileDescriptor, options: StatOptions = js.native): Stats
Synchronous fstat(2).
Synchronous fstat(2).
- fd
the file descriptor
- returns
an instance of fs.Stats.
- def fsync(fd: FileDescriptor, callback: FsCallback0): Unit
Asynchronous fsync(2).
Asynchronous fsync(2). No arguments other than a possible exception are given to the completion callback.
- fd
the file descriptor
- callback
the completion callback.
- def fsyncSync(fd: FileDescriptor): Unit
Synchronous fsync(2).
Synchronous fsync(2).
- fd
the file descriptor
- returns
undefined.
- def ftruncate(fd: FileDescriptor, length: Int, callback: FsCallback0): Unit
Asynchronous ftruncate(2).
Asynchronous ftruncate(2). No arguments other than a possible exception are given to the completion callback. If the file referred to by the file descriptor was larger than length bytes, only the first length bytes will be retained in the file.
- fd
the file descriptor
- length
the desired length
- callback
the completion callback.
- def ftruncate(fd: FileDescriptor, callback: FsCallback0): Unit
Asynchronous ftruncate(2).
Asynchronous ftruncate(2). No arguments other than a possible exception are given to the completion callback. If the file referred to by the file descriptor was larger than length bytes, only the first length bytes will be retained in the file.
- fd
the file descriptor
- callback
the completion callback.
- def ftruncateSync(fd: FileDescriptor, length: Int = 0): Unit
Synchronous ftruncate(2).
Synchronous ftruncate(2).
- fd
the file descriptor
- length
the desired length
- returns
undefined.
- def futimes(fd: FileDescriptor, atime: Time, mtime: Time, callback: Function): Unit
Change the file timestamps of a file referenced by the supplied file descriptor.
Change the file timestamps of a file referenced by the supplied file descriptor.
fs.futimes(fd, atime, mtime, callback)
Example: - def futimesSync(fd: FileDescriptor, atime: Time, mtime: Time): Unit
Synchronous version of fs.futimes().
Synchronous version of fs.futimes().
- returns
undefined.
fs.futimesSync(fd, atime, mtime)
Example: - final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def getMaxListeners(): Int
Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.
Returns the current max listener value for the EventEmitter which is either set by emitter.setMaxListeners(n) or defaults to EventEmitter.defaultMaxListeners.
- Definition Classes
- IEventEmitter
emitter.getMaxListeners()
- See also
setMaxListeners()
Example: - def hasOwnProperty(v: String): Boolean
- Definition Classes
- Object
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def isPrototypeOf(v: Object): Boolean
- Definition Classes
- Object
- def lchmod(path: Path, mode: FileMode, callback: FsCallback0): Unit
Asynchronous lchmod(2).
Asynchronous lchmod(2). No arguments other than a possible exception are given to the completion callback.
fs.lchmod(path, mode, callback)
Example: - def lchmodSync(path: Path, mode: FileMode): Unit
Synchronous lchmod(2).
Synchronous lchmod(2).
- path
the path (Buffer | String)
- mode
the mode (Integer)
- returns
undefined.
fs.lchmodSync(path, mode)
Example: - def lchown(path: Path, uid: UID, gid: GID, callback: FsCallback0): Unit
Asynchronous lchown(2).
Asynchronous lchown(2). No arguments other than a possible exception are given to the completion callback.
- path
the path (Buffer | String)
- uid
the user ID
- gid
the group ID
- callback
the completion callback.
fs.lchown(path, uid, gid, callback)
Example: - def lchownSync(path: Path, uid: UID, gid: GID): Unit
Synchronous chown(2).
Synchronous chown(2).
- path
the path (Buffer | String)
- uid
the user ID
- gid
the group ID
- returns
undefined.
- def link(existingPath: Path, newPath: Path, callback: FsCallback0): Unit
Asynchronous link(2).
Asynchronous link(2). No arguments other than a possible exception are given to the completion callback.
- existingPath
the existing path
- newPath
the new path
- callback
the completion callback.
fs.link(srcpath, dstpath, callback)
Example: - def linkSync(existingPath: Path, newPath: Path): Unit
Synchronous link(2).
Synchronous link(2).
- existingPath
the existing path
- newPath
the new path
- returns
undefined.
- def listenerCount(eventName: String): Int
Returns the number of listeners listening to the event named eventName.
Returns the number of listeners listening to the event named eventName.
- Definition Classes
- IEventEmitter
emitter.listenerCount(eventName)
Example: - def listeners(eventName: String): Array[Function]
Returns a copy of the array of listeners for the event named eventName.
Returns a copy of the array of listeners for the event named eventName.
- Definition Classes
- IEventEmitter
emitter.listeners(eventName)
Example: - def lstat(path: Path, callback: FsCallback1[Stats]): Unit
Asynchronous lstat(2).
Asynchronous lstat(2). 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.
- path
the path (Buffer | String)
- callback
The callback gets two arguments (err, stats) where stats is a fs.Stats object.
- def lstatSync(path: Path): Stats
Synchronous lstat(2).
Synchronous lstat(2).
- path
the path (Buffer | String)
- returns
an instance of fs.Stats.
- def mkdir(path: Path, callback: FsCallback0): Unit
Asynchronous mkdir(2).
Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0o777.
fs.mkdir(path[, mode], callback)
Example: - def mkdir(path: Path, mode: FileMode, callback: FsCallback0): Unit
Asynchronous mkdir(2).
Asynchronous mkdir(2). No arguments other than a possible exception are given to the completion callback. mode defaults to 0o777.
fs.mkdir(path[, mode], callback)
Example: - def mkdirSync(path: Path, mode: FileMode = js.native): Unit
Synchronous mkdir(2).
Synchronous mkdir(2).
- path
the path
- mode
the mode
- def mkdtemp(prefix: String, callback: FsCallback1[String]): Unit
Creates a unique temporary directory.
Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. The created folder path is passed as a string to the callback's second parameter. The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use.
- prefix
the prefix
- callback
the callback
fs.mkdtemp(prefix[, options], callback)
Example: - def mkdtemp(prefix: String, options: |[String, FileEncodingOptions], callback: FsCallback1[String]): Unit
Creates a unique temporary directory.
Creates a unique temporary directory. Generates six random characters to be appended behind a required prefix to create a unique temporary directory. The created folder path is passed as a string to the callback's second parameter. The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use.
- prefix
the prefix
- options
the optional encoding setting
- callback
the callback
fs.mkdtemp(prefix[, options], callback)
Example: - def mkdtempSync(prefix: String, options: |[String, FileEncodingOptions] = js.native): String
The synchronous version of fs.mkdtemp().
The synchronous version of fs.mkdtemp(). Returns the created folder path. The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use.
- prefix
the prefix
- options
the optional encoding setting
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def on(eventName: String, listener: Function): Fs.this.type
Adds the listener function to the end of the listeners array for the event named eventName.
Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.
Returns a reference to the EventEmitter so calls can be chained.
- Definition Classes
- IEventEmitter
emitter.on(eventName, listener)
Example: - def once(eventName: String, listener: Function): Fs.this.type
Adds a one time listener function for the event named eventName.
Adds a one time listener function for the event named eventName. This listener is invoked only the next time eventName is triggered, after which it is removed.
- Definition Classes
- IEventEmitter
emitter.once(eventName, listener)
Example: - def open(path: Path, flags: Flags, callback: FsCallback1[FileDescriptor]): Unit
Asynchronous file open.
Asynchronous file open. See open(2).
- path
the path (Buffer | String)
- flags
flags can be:
- 'r' - Open file for reading. An exception occurs if the file does not exist.
- 'r+' - Open file for reading and writing. An exception occurs if the file does not exist.
- 'rs+' - Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache. This is primarily useful for opening files on NFS mounts as it allows you to skip the potentially stale local cache. It has a very real impact on I/O performance so don't use this flag unless you need it. Note that this doesn't turn fs.open() into a synchronous blocking call. If that's what you want then you should be using fs.openSync()
- 'w' - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
- 'wx' - Like 'w' but fails if path exists.
- 'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
- 'wx+' - Like 'w+' but fails if path exists.
- 'a' - Open file for appending. The file is created if it does not exist.
- 'ax' - Like 'a' but fails if path exists.
- 'a+' - Open file for reading and appending. The file is created if it does not exist.
- 'ax+' - Like 'a+' but fails if path exists.
- callback
the callback gets two arguments (err, fd)
fs.open(path, flags[, mode], callback)
Example: - def open(path: Path, flags: Flags, mode: FileMode, callback: FsCallback1[FileDescriptor]): Unit
Asynchronous file open.
Asynchronous file open. See open(2).
- path
the path (Buffer | String)
- flags
flags can be:
- 'r' - Open file for reading. An exception occurs if the file does not exist.
- 'r+' - Open file for reading and writing. An exception occurs if the file does not exist.
- 'rs+' - Open file for reading and writing in synchronous mode. Instructs the operating system to bypass the local file system cache. This is primarily useful for opening files on NFS mounts as it allows you to skip the potentially stale local cache. It has a very real impact on I/O performance so don't use this flag unless you need it. Note that this doesn't turn fs.open() into a synchronous blocking call. If that's what you want then you should be using fs.openSync()
- 'w' - Open file for writing. The file is created (if it does not exist) or truncated (if it exists).
- 'wx' - Like 'w' but fails if path exists.
- 'w+' - Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists).
- 'wx+' - Like 'w+' but fails if path exists.
- 'a' - Open file for appending. The file is created if it does not exist.
- 'ax' - Like 'a' but fails if path exists.
- 'a+' - Open file for reading and appending. The file is created if it does not exist.
- 'ax+' - Like 'a+' but fails if path exists.
- mode
sets the file mode (permission and sticky bits), but only if the file was created. It defaults to 0666, readable and writable.
- callback
the callback gets two arguments (err, fd)
fs.open(path, flags[, mode], callback)
Example: - def openSync(path: Path, flags: Flags, mode: FileMode = js.native): FileDescriptor
Synchronous version of fs.open().
Synchronous version of fs.open().
- path
the path (Buffer | String)
- flags
the flags
- mode
the file mode
- returns
an integer representing the file descriptor.
fs.openSync(path, flags[, mode])
Example: - def prependListener(eventName: String, listener: Function): Fs.this.type
- Definition Classes
- IEventEmitter
- def prependOnceListener(eventName: String, listener: Function): Fs.this.type
- Definition Classes
- IEventEmitter
- def propertyIsEnumerable(v: String): Boolean
- Definition Classes
- Object
- def read(fd: FileDescriptor, buffer: Buffer, offset: |[Int, Null], length: |[Int, Null], position: |[Int, Null], callback: FsCallback2[Int, Buffer]): Unit
Read data from the file specified by fd.
Read data from the file specified by fd.
- fd
is the file descriptor
- buffer
is the buffer that the data will be written to.
- offset
is the offset in the buffer to start writing at.
- length
is an integer specifying the number of bytes to read.
- position
is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.
- callback
the callback is given the three arguments, (err, bytesRead, buffer).
- def readFile(file: |[Path, FileDescriptor], callback: FsCallback1[Buffer]): Unit
Asynchronously reads the entire contents of a file.
Asynchronously reads the entire contents of a file.
- file
filename or file descriptor
- callback
The callback is passed two arguments (err, data), where data is the contents of the file. If no encoding is specified, then the raw buffer is returned.
fs.readFile(file[, options], callback)
Example: - def readFile(file: |[Path, FileDescriptor], encoding: String, callback: FsCallback1[String]): Unit
Asynchronously reads the entire contents of a file.
Asynchronously reads the entire contents of a file.
- file
filename or file descriptor
- encoding
the encoding (default = null)
- callback
The callback is passed two arguments (err, data), where data is the contents of the file. If no encoding is specified, then the raw buffer is returned.
fs.readFile(file[, options], callback)
Example: - def readFile(file: |[Path, FileDescriptor], options: ReadFileOptions, callback: FsCallback1[Output]): Unit
Asynchronously reads the entire contents of a file.
Asynchronously reads the entire contents of a file.
- file
filename or file descriptor
- options
the optional settings
- callback
The callback is passed two arguments (err, data), where data is the contents of the file. If no encoding is specified, then the raw buffer is returned.
fs.readFile(file[, options], callback)
Example: - def readFileSync(file: |[Path, FileDescriptor]): Buffer
Synchronous version of fs.readFile.
Synchronous version of fs.readFile.
- file
filename or file descriptor <String> | <Buffer> | <Integer>
- returns
the contents of the file. If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
fs.readFileSync(file[, options])
Example: - def readFileSync(file: |[Path, FileDescriptor], options: ReadFileOptions = js.native): Output
Synchronous version of fs.readFile.
Synchronous version of fs.readFile. Returns the contents of the file.
- file
filename or file descriptor <String> | <Buffer> | <Integer>
- options
the optional encoding <Object> | <String>
- returns
the contents of the file. If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
fs.readFileSync(file[, options])
Example: - def readFileSync(file: |[Path, FileDescriptor], encoding: String): String
Synchronous version of fs.readFile.
Synchronous version of fs.readFile. Returns the contents of the file.
- file
filename or file descriptor <String> | <Buffer> | <Integer>
- encoding
the optional encoding <Object> | <String>
- returns
the contents of the file. If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.
fs.readFileSync(file[, options])
Example: - def readSync(fd: FileDescriptor, buffer: Buffer, offset: Int, length: Int, position: Int): Int
Synchronous version of fs.read().
Synchronous version of fs.read().
- fd
is the file descriptor
- buffer
is the buffer that the data will be written to.
- offset
is the offset in the buffer to start writing at.
- length
is an integer specifying the number of bytes to read.
- position
is an integer specifying where to begin reading from in the file. If position is null, data will be read from the current file position.
- returns
the number of bytesRead.
- def readdir(path: Path, callback: FsCallback1[Array[String]]): Unit
Asynchronous readdir(3).
Asynchronous readdir(3). Reads the contents of a directory.
- path
the path (Buffer | String)
- callback
the callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.
fs.readdir(path[, options], callback)
Example: - def readdir(path: Path, options: |[String, FileEncodingOptions], callback: FsCallback1[ReaddirArrays]): Unit
Asynchronous readdir(3).
Asynchronous readdir(3). Reads the contents of a directory.
- path
the path (Buffer | String)
- options
the optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the filenames passed to the callback. If the encoding is set to 'buffer', the filenames returned will be passed as Buffer objects.
- callback
the callback gets two arguments (err, files) where files is an array of the names of the files in the directory excluding '.' and '..'.
fs.readdir(path[, options], callback)
Example: - def readdirSync(path: Path, options: |[String, ReaddirOptions] = js.native): Array[String]
Synchronous readdir(3).
Synchronous readdir(3).
- path
the path (Buffer | String)
- options
the optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the filenames passed to the callback. If the encoding is set to 'buffer', the filenames returned will be passed as Buffer objects.
- returns
an array of filenames excluding '.' and '..'.
- def readlink(path: Path, callback: FsCallback1[String]): Unit
- def readlink(path: Path, options: |[String, FileEncodingOptions], callback: FsCallback1[Output]): Unit
Asynchronous readlink(2).
Asynchronous readlink(2). If the encoding is set to 'buffer', the link path returned will be passed as a Buffer object.
- path
the path (Buffer | String)
- options
the optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the link path passed to the callback.
- callback
the callback gets two arguments (err, linkString).
fs.readlink(path[, options], callback)
Example: - def readlinkSync(path: Path): String
- def readlinkSync(path: Path, options: |[String, FileEncodingOptions]): Output
Synchronous readlink(2).
Synchronous readlink(2).
- path
the path (Buffer | String)
- options
the optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the link path passed to the callback. If the encoding is set to 'buffer', the link path returned will be passed as a Buffer object.
- returns
the symbolic link's string value.
- def realpath(path: Path, callback: FsCallback1[String]): Unit
Asynchronous realpath(2).
Asynchronous realpath(2). The callback gets two arguments (err, resolvedPath). May use process.cwd to resolve relative paths.
The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the path passed to the callback. If the encoding is set to 'buffer', the path returned will be passed as a Buffer object.
fs.realpath(path[, options], callback)
Example: - def realpath(path: Path, options: |[String, FileEncodingOptions], callback: FsCallback1[Output]): Unit
Asynchronous realpath(2).
Asynchronous realpath(2). May use process.cwd to resolve relative paths.
- path
the path
- options
The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the path passed to the callback.
- callback
The callback gets two arguments (err, resolvedPath). If the encoding is set to 'buffer', the path returned will be passed as a Buffer object.
fs.realpath(path[, options], callback)
Example: - def realpathSync(path: Path): String
- def realpathSync(path: Path, options: FileEncodingOptions = js.native): Output
Synchronous realpath(3).
Synchronous realpath(3). Only paths that can be converted to UTF8 strings are supported. The optional options argument can be a string specifying an encoding, or an object with an encoding property specifying the character encoding to use for the returned value. If the encoding is set to 'buffer', the path returned will be passed as a Buffer object.
- returns
the resolved path.
fs.realpathSync(path[, options])
Example: - def removeAllListeners(eventName: String = js.native): Fs.this.type
Removes all listeners, or those of the specified eventName.
Removes all listeners, or those of the specified eventName.
Note that it is bad practice to remove listeners added elsewhere in the code, particularly when the EventEmitter instance was created by some other component or module (e.g. sockets or file streams).
Returns a reference to the EventEmitter so calls can be chained.
- Definition Classes
- IEventEmitter
emitter.removeAllListeners([eventName])
Example: - def removeListener(eventName: String, listener: Function): Fs.this.type
Removes the specified listener from the listener array for the event named eventName.
Removes the specified listener from the listener array for the event named eventName. removeListener will remove, at most, one instance of a listener from the listener array. If any single listener has been added multiple times to the listener array for the specified eventName, then removeListener must be called multiple times to remove each instance.
Note that once an event has been emitted, all listeners attached to it at the time of emitting will be called in order. This implies that any removeListener() or removeAllListeners() calls after emitting and before the last listener finishes execution will not remove them from emit() in progress. Subsequent events will behave as expected.
- Definition Classes
- IEventEmitter
emitter.removeListener(eventName, listener)
Example: - def rename(oldPath: Path, newPath: Path, callback: FsCallback0): Unit
Asynchronous rename(2).
Asynchronous rename(2). No arguments other than a possible exception are given to the completion callback.
fs.rename(oldPath, newPath, callback)
Example: - def renameSync(oldPath: Path, newPath: Path): Unit
Synchronous rename(2).
Synchronous rename(2).
- returns
undefined.
fs.renameSync(oldPath, newPath)
Example: - def rmdir(path: Path, callback: FsCallback0): Unit
Asynchronous rmdir(2).
Asynchronous rmdir(2). No arguments other than a possible exception are given to the completion callback.
fs.rmdir(path, callback)
Example: - def rmdirSync(path: Path): Unit
Synchronous rmdir(2rmdir).
Synchronous rmdir(2rmdir).
- returns
undefined.
fs.rmdirSync(path)
Example: - def setMaxListeners(n: Int): Fs.this.type
By default EventEmitters will print a warning if more than 10 listeners are added for a particular event.
By default EventEmitters will print a warning if more than 10 listeners are added for a particular event. This is a useful default that helps finding memory leaks. Obviously, not all events should be limited to just 10 listeners. The emitter.setMaxListeners() method allows the limit to be modified for this specific EventEmitter instance. The value can be set to Infinity (or 0) for to indicate an unlimited number of listeners.
Returns a reference to the EventEmitter so calls can be chained.
- Definition Classes
- IEventEmitter
emitter.setMaxListeners(n)
Example: - def stat(path: Path, callback: FsCallback1[Stats]): Stats
Asynchronous stat(2).
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.
fs.stat(path, callback)
Example: - def statSync(path: Path): Stats
Synchronous stat(2).
Synchronous stat(2). Returns an instance of fs.Stats.
fs.statSync(path)
Example: - def symlink(target: Path, path: Path, callback: FsCallback0): Unit
Asynchronous symlink(2).
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.
fs.symlink(target, path[, type], callback)
Example: - def symlink(target: Path, path: Path, type: String, callback: FsCallback0): Unit
Asynchronous symlink(2).
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.
fs.symlink(target, path[, type], callback)
Example: - def symlinkSync(target: Path, path: Path, type: String = js.native): Unit
Synchronous symlink(2).
Synchronous symlink(2).
- returns
undefined.
fs.symlinkSync(target, path[, type])
Example: - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toLocaleString(): String
- Definition Classes
- Object
- def toString(): String
- Definition Classes
- AnyRef → Any
- def truncate(path: Path, callback: FsCallback0): Unit
- def truncate(path: Path, length: Int, callback: FsCallback0): Unit
Asynchronous truncate(2).
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.
- path
the path <String> | <Buffer>
- length
the length
- callback
the completion callback.
fs.truncate(path, length, callback)
Example: - def truncateSync(path: Path, length: Int = js.native): Unit
Synchronous truncate(2).
Synchronous truncate(2). In this case, fs.ftruncateSync() is called.
- path
the path or file descriptor - <String> | <Buffer> | <Integer>
- length
the length
- returns
undefined.
fs.truncateSync(path, length)
Example: - def unlink(path: Path, callback: FsCallback0): Unit
Asynchronous unlink(2).
Asynchronous unlink(2). No arguments other than a possible exception are given to the completion callback.
fs.unlink(path, callback)
Example: - def unlinkSync(path: Path): Unit
Synchronous unlink(2).
Synchronous unlink(2).
- returns
undefined.
fs.unlinkSync(path)
Example: - def unwatchFile(path: Path, listener: FsCallback0 = js.native): Unit
Stop watching for changes on filename.
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.
Calling fs.unwatchFile() with a filename that is not being watched is a no-op, not an error.
Note: fs.watch() is more efficient than fs.watchFile() and fs.unwatchFile(). fs.watch() should be used instead of fs.watchFile() and fs.unwatchFile() when possible.
fs.unwatchFile(filename[, listener])
Example: - val usingDomains: Boolean
- Definition Classes
- IEventEmitter
- def utimes(path: Path, atime: Time, mtime: Time, callback: FsCallback0): Unit
Change file timestamps of the file referenced by the supplied path.
Change file timestamps of the file referenced by the supplied path.
Note: the arguments atime and mtime of the following related functions does follow the below rules:
If the value is a numberable string like '123456789', the value would get converted to corresponding number. If the value is NaN or Infinity, the value would get converted to Date.now().
fs.utimes(path, atime, mtime, callback)
Example: - def utimesSync(path: Path, atime: Time, mtime: Time): Unit
Synchronous version of fs.utimes().
Synchronous version of fs.utimes().
- returns
undefined.
fs.utimesSync(path, atime, mtime)
Example: - def valueOf(): Any
- Definition Classes
- Object
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def watch(filename: Path, options: FSWatcherOptions = js.native): FSWatcher
Watch for changes on filename, where filename is either a file or a directory.
Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher.
The second argument is optional. If options is provided as a string, it specifies the encoding. Otherwise options should be passed as an object.
The listener callback gets two arguments (event, filename). event is either 'rename' or 'change', and filename is the name of the file which triggered the event.
- filename
the filename (Buffer | String)
- options
- returns
fs.watch(filename[, options][, listener])
Example: - def watch(filename: Path, listener: Function2[EventType, String, Any]): FSWatcher
Watch for changes on filename, where filename is either a file or a directory.
Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher.
The second argument is optional. If options is provided as a string, it specifies the encoding. Otherwise options should be passed as an object.
The listener callback gets two arguments (event, filename). event is either 'rename' or 'change', and filename is the name of the file which triggered the event.
- filename
the filename (Buffer | String)
- listener
the listener callback gets two arguments (eventType, filename). eventType is either 'rename' or 'change', and filename is the name of the file which triggered the event.
- returns
fs.watch(filename[, options][, listener])
Example: - def watch(filename: Path, options: FSWatcherOptions, listener: Function2[EventType, String, Any]): FSWatcher
Watch for changes on filename, where filename is either a file or a directory.
Watch for changes on filename, where filename is either a file or a directory. The returned object is a fs.FSWatcher.
The second argument is optional. If options is provided as a string, it specifies the encoding. Otherwise options should be passed as an object.
The listener callback gets two arguments (event, filename). event is either 'rename' or 'change', and filename is the name of the file which triggered the event.
- filename
the filename (Buffer | String)
- options
- listener
the callback function
- returns
fs.watch(filename[, options][, listener])
Example: - def watchFile(filename: Path, listener: Function2[Stats, Stats, Any]): Unit
Watch for changes on filename.
Watch for changes on filename. The callback listener will be called each time the file is accessed.
The options argument may be omitted. If provided, it should be an object. The options object may contain a boolean named persistent that indicates whether the process should continue to run as long as files are being watched. The options object may specify an interval property indicating how often the target should be polled in milliseconds. The default is { persistent: true, interval: 5007 }.
- filename
the filename (Buffer | String)
- listener
the callback
- def watchFile(filename: Path, options: FileWatcherOptions, listener: Function2[Stats, Stats, Any]): Unit
Watch for changes on filename.
Watch for changes on filename. The callback listener will be called each time the file is accessed.
The options argument may be omitted. If provided, it should be an object. The options object may contain a boolean named persistent that indicates whether the process should continue to run as long as files are being watched. The options object may specify an interval property indicating how often the target should be polled in milliseconds. The default is { persistent: true, interval: 5007 }.
- filename
the filename (Buffer | String)
- options
- listener
the callback
- def write(fd: FileDescriptor, string: String, callback: FsCallback2[Int, String]): Unit
- def write(fd: FileDescriptor, string: String, position: Int, callback: FsCallback2[Int, String]): Unit
- def write(fd: FileDescriptor, string: String, position: Int, encoding: String, callback: FsCallback2[Int, String]): Unit
Write string to the file specified by fd.
Write string to the file specified by fd. If string is not a string, then the value will be coerced to one. Unlike when writing buffer, the entire string must be written. No substring may be specified. This is because the byte offset of the resulting data may not be the same as the string offset. Note that it is unsafe to use fs.write multiple times on the same file without waiting for the callback. For this scenario, fs.createWriteStream is strongly recommended. On Linux, positional writes don't work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.
- fd
the file descriptor
- string
the data to write
- position
refers to the offset from the beginning of the file where this data should be written. If typeof position !== 'number' the data will be written at the current position. See pwrite(2).
- encoding
is the expected string encoding.
- callback
will receive the arguments (err, written, string) where written specifies how many bytes the passed string required to be written. Note that bytes written is not the same as string characters. See Buffer.byteLength.
fs.write(fd, string[, position[, encoding]], callback)
Example: - def write(fd: FileDescriptor, buffer: Uint8Array, offset: |[Int, Null], length: |[Int, Null], position: |[Int, Null], callback: FsCallback2[Int, Buffer]): Unit
Write buffer to the file specified by fd.
Write buffer to the file specified by fd.
Note: that it is unsafe to use fs.write multiple times on the same file without waiting for the callback. For this scenario, fs.createWriteStream is strongly recommended.
On Linux, positional writes don't work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.
- fd
the file descriptor
- buffer
the buffer containing the data to write
- offset
determines the part of the buffer to be written, and length is an integer specifying the number of bytes to write.
- length
the optional length of the data to write
- position
refers to the offset from the beginning of the file where this data should be written. If typeof position !== 'number', the data will be written at the current position. See pwrite(2).
- callback
will be given three arguments (err, written, buffer) where written specifies how many bytes were written from buffer.
fs.write(fd, buffer[, offset[, length[, position]]], callback)
Example: - def writeFile(file: String, data: String, callback: FsCallback0): Unit
- def writeFile(file: String, data: String, options: FileWriteOptions, callback: FsCallback0): Unit
- def writeFile(file: String, data: Uint8Array, callback: FsCallback0): Unit
- def writeFile(file: String, data: Uint8Array, options: FileWriteOptions, callback: FsCallback0): Unit
Asynchronously writes data to a file, replacing the file if it already exists.
Asynchronously writes data to a file, replacing the file if it already exists. data can be a string or a buffer. The encoding option is ignored if data is a buffer. It defaults to 'utf8'
fs.writeFile(file, data[, options], callback)
Example: - def writeFileSync(file: |[Path, FileDescriptor], data: String): Unit
- def writeFileSync(file: |[Path, FileDescriptor], data: String, options: FileWriteOptions): Unit
- def writeFileSync(file: |[Path, FileDescriptor], data: Uint8Array, options: FileWriteOptions = js.native): Unit
The synchronous version of fs.writeFile().
The synchronous version of fs.writeFile().
- returns
undefined.
fs.writeFileSync(file, data[, options])
Example: - def writeSync(fd: FileDescriptor, data: String): Unit
- def writeSync(fd: FileDescriptor, data: String, encoding: String): Unit
- def writeSync(fd: FileDescriptor, data: String, position: Int): Unit
- def writeSync(fd: FileDescriptor, data: String, position: Int, encoding: String): Unit
Write string to the file specified by fd.
Write string to the file specified by fd.
- fd
the given file descriptor
- data
the given string
- position
refers to the offset from the beginning of the file where this data should be written.
- encoding
is the expected string encoding.
fs.writeSync(fd, string[, position[, encoding]])
Example: - def writeSync(fd: FileDescriptor, buffer: BufferLike): Unit
- def writeSync(fd: FileDescriptor, buffer: BufferLike, offset: Int): Unit
- def writeSync(fd: FileDescriptor, buffer: BufferLike, offset: Int, length: Int): Unit
- def writeSync(fd: FileDescriptor, buffer: BufferLike, offset: Int, length: Int, position: Int): Unit
- def writeSync(fd: FileDescriptor, buffer: Uint8Array): Unit
- def writeSync(fd: FileDescriptor, buffer: Uint8Array, offset: Int): Unit
- def writeSync(fd: FileDescriptor, buffer: Uint8Array, offset: Int, length: Int, position: Int = js.native): Unit
Write buffer to the file specified by fd.
Write buffer to the file specified by fd.
- fd
the given file descriptor
- buffer
the given buffer
- offset
determines the part of the buffer to be written, and length is an integer specifying the number of bytes to write.
- length
the optional length of the data to write
- position
refers to the offset from the beginning of the file where this data should be written.
fs.writeSync(fd, buffer[, offset[, length[, position]]])
Example: