mirror of
https://github.com/nodejs/node.git
synced 2026-10-28 18:25:13 +08:00
Add fs.mkstemp(), fs.mkstempSync() and fsPromises.mkstemp(), which create and open a unique temporary file in one operation. They expose uv_fs_mkstemp(), the file counterpart of the function behind fs.mkdtemp(). The callback and sync versions return the path and a file descriptor, the promise version returns the path and a FileHandle. libuv clears the path of the request when mkstemp() fails, so the template is saved in the request and used for the path of the error. The functions are also supported on mounted virtual file systems. Refs: https://github.com/nodejs/node/pull/33549 Refs: https://github.com/nodejs/node/issues/33890 Refs: https://github.com/nodejs/node/issues/5332 Signed-off-by: marcopiraccini <marco.piraccini@gmail.com> PR-URL: https://github.com/nodejs/node/pull/66484 Reviewed-By: Paolo Insogna <paolo@cowtech.it> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
89 lines
2.0 KiB
JavaScript
89 lines
2.0 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('node:assert');
|
|
const fs = require('node:fs');
|
|
const tmpdir = require('../common/tmpdir');
|
|
|
|
const testPath = tmpdir.resolve('assert-encoding-error');
|
|
const options = 'test';
|
|
const expectedError = {
|
|
code: 'ERR_INVALID_ARG_VALUE',
|
|
name: 'TypeError',
|
|
};
|
|
|
|
assert.throws(() => {
|
|
fs.readFile(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.readFileSync(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.readdir(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.readdirSync(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.readlink(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.readlinkSync(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.writeFile(testPath, 'data', options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.writeFileSync(testPath, 'data', options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.appendFile(testPath, 'data', options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.appendFileSync(testPath, 'data', options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.watch(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.realpath(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.realpathSync(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.mkdtemp(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.mkdtempSync(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.mkstemp(testPath, options, common.mustNotCall());
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.mkstempSync(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.ReadStream(testPath, options);
|
|
}, expectedError);
|
|
|
|
assert.throws(() => {
|
|
fs.WriteStream(testPath, options);
|
|
}, expectedError);
|