温馨提示:本站仅提供公开网络链接索引服务,不存储、不篡改任何第三方内容,所有内容版权归原作者所有
AI智能索引来源:http://www.bun.com/reference/node/fs/appendFile
点击访问原文链接

Node fs.appendFile function | API Reference | Bun

Node fs.appendFile function | API Reference | BunBuildDocsReferenceGuidesBlogDiscord/node:fs/appendFileNappendFile

Search the reference...

/

BuildDocsReferenceGuidesBlogDiscord/node:fs/appendFileNappendFile

namespace

fs.appendFile { if (err) throw err; console.log('The "data to append" was appended to file!'); }); ``` If `options` is a string, then it specifies the encoding: ```js 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. ```js 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; } }); ```" data-algolia-static="false" data-algolia-merged="true" data-type="Namespace">function appendFile(path: PathOrFileDescriptor,data: string | Uint8ArrayArrayBufferLike>,options: WriteFileOptions,callback: NoParamCallback): void;

Asynchronously 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;
}
});
@param path

filename or file descriptor

function appendFile(file: PathOrFileDescriptor,data: string | Uint8ArrayArrayBufferLike>,callback: NoParamCallback): void;

Asynchronously append data to a file, creating the file if it does not exist.

@param 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.

@param data

The data to write. If something other than a Buffer or Uint8Array is provided, the value is coerced to a string.

namespace appendFile

Resources

ReferenceDocsGuidesDiscordMerch StoreGitHubBlog 

Toolkit

RuntimePackage managerTest runnerBundlerPackage runner

Project

Bun 1.0Bun 1.1Bun 1.2Bun 1.3RoadmapContributingLicense

Baked with ❤️ in San Francisco

We're hiring →

Node fs.appendFile function | API Reference | Bun,AI智能索引,全网链接索引,智能导航,网页索引

    API documentation for namespace node:fs.appendFile | Bun