AppendFile
[<Interface>]
type AppendFile =
abstract member Invoke (file: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: NoParamCallback) : unit
abstract member Invoke (path: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, options: WriteFileOptions, callback: NoParamCallback) : unit
abstract member __promisify__ (file: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?options: U2<string,WriteFileOptions2>) : Promise<unit>| Assembly | Xantham.Fable.Node |
Methods
abstract member Invoke (file: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: NoParamCallback) : unit
abstract member Invoke (file: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, callback: NoParamCallback) : unitAsynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a Buffer.
The mode option only affects the newly created file. See open for more details.
import { appendFile } from 'node:fs';
appendFile('message.txt', 'data to append', (err) => {
if (err) throw err;
console.log('The "data to append" was appended to file!');
});
If options is a string, then it specifies the encoding:
import { appendFile } from 'node:fs';
appendFile('message.txt', 'data to append', 'utf8', callback);
The path may be specified as a numeric file descriptor that has been opened for appending (using fs.open() or fs.openSync()). The file descriptor will not be closed automatically.
import { open, close, appendFile } from 'node:fs';
function closeFd(fd) {
close(fd, (err) => {
if (err) throw err;
});
}
open('message.txt', 'a', (err, fd) => {
if (err) throw err;
try {
appendFile(fd, 'data to append', 'utf8', (err) => {
closeFd(fd);
if (err) throw err;
});
} catch (err) {
closeFd(fd);
throw err;
}
});
Asynchronously append data to a file, creating the file if it does not exist.
| Parameter | |
|---|---|
path | filename or file descriptor |
file | A path to a file. If a URL is provided, it must use the file: protocol. If a file descriptor is provided, the underlying file will not be closed automatically. |
data | The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string. |
abstract member Invoke (path: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, options: WriteFileOptions, callback: NoParamCallback) : unit
abstract member Invoke (path: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, options: WriteFileOptions, callback: NoParamCallback) : unitAsynchronously append data to a file, creating the file if it does not yet exist. data can be a string or a Buffer.
The mode option only affects the newly created file. See open for more details.
import { appendFile } from 'node:fs';
appendFile('message.txt', 'data to append', (err) => {
if (err) throw err;
console.log('The "data to append" was appended to file!');
});
If options is a string, then it specifies the encoding:
import { appendFile } from 'node:fs';
appendFile('message.txt', 'data to append', 'utf8', callback);
The path may be specified as a numeric file descriptor that has been opened for appending (using fs.open() or fs.openSync()). The file descriptor will not be closed automatically.
import { open, close, appendFile } from 'node:fs';
function closeFd(fd) {
close(fd, (err) => {
if (err) throw err;
});
}
open('message.txt', 'a', (err, fd) => {
if (err) throw err;
try {
appendFile(fd, 'data to append', 'utf8', (err) => {
closeFd(fd);
if (err) throw err;
});
} catch (err) {
closeFd(fd);
throw err;
}
});
Asynchronously append data to a file, creating the file if it does not exist.
@since v0.6.7
| Parameter | |
|---|---|
path | filename or file descriptor |
file | A path to a file. If a URL is provided, it must use the file: protocol. If a file descriptor is provided, the underlying file will not be closed automatically. |
data | The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string. |
abstract member __promisify__ (file: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?options: U2<string,WriteFileOptions2>) : Promise<unit>
abstract member __promisify__ (file: PathOrFileDescriptor, data: U2<string,Uint8Array<U2<ArrayBuffer,SharedArrayBuffer>>>, ?options: U2<string,WriteFileOptions2>) : Promise<unit>Asynchronously append data to a file, creating the file if it does not exist.
| Parameter | |
|---|---|
file | A path to a file. If a URL is provided, it must use the file: protocol. URL support is experimental. If a file descriptor is provided, the underlying file will not be closed automatically. |
data | The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string. |
options | Either the encoding for the file, or an object optionally specifying the encoding, file mode, and flag. If encoding is not supplied, the default of 'utf8' is used. If mode is not supplied, the default of 0o666 is used. If mode is a string, it is parsed as an octal integer. If flag is not supplied, the default of 'a' is used. |