1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-20 20:42:19 -05:00

fix(ext/node): add FileHandle#datasync & FileHandle#sync

This commit is contained in:
zhangyongsheng.dev__dcar 2025-01-15 13:26:42 +08:00
parent b22a50cb0c
commit a75cd2a9d6
3 changed files with 51 additions and 0 deletions

View file

@ -158,6 +158,14 @@ export class FileHandle extends EventEmitter {
return promises.chmod(this.#path, mode);
}
datasync(): Promise<void> {
return fsCall(promises.fdatasync, this);
}
sync(): Promise<void> {
return fsCall(promises.fsync, this);
}
utimes(
atime: number | string | Date,
mtime: number | string | Date,

View file

@ -480,6 +480,7 @@
"test-fs-opendir.js",
"test-fs-promises-exists.js",
"test-fs-promises-file-handle-stat.js",
"test-fs-promises-file-handle-sync.js",
"test-fs-promises-file-handle-write.js",
"test-fs-promises-readfile-empty.js",
"test-fs-promises-readfile-with-fd.js",

View file

@ -0,0 +1,42 @@
// deno-fmt-ignore-file
// deno-lint-ignore-file
// Copyright Joyent and Node contributors. All rights reserved. MIT license.
// Taken from Node 20.11.1
// This file is automatically generated by `tests/node_compat/runner/setup.ts`. Do not modify this file manually.
'use strict';
require('../common');
const assert = require('assert');
const fixtures = require('../common/fixtures');
const tmpdir = require('../common/tmpdir');
const { access, copyFile, open } = require('fs').promises;
async function validate() {
tmpdir.refresh();
const dest = tmpdir.resolve('baz.js');
await assert.rejects(
copyFile(fixtures.path('baz.js'), dest, 'r'),
{
code: 'ERR_INVALID_ARG_TYPE',
}
);
await copyFile(fixtures.path('baz.js'), dest);
await assert.rejects(
access(dest, 'r'),
{ code: 'ERR_INVALID_ARG_TYPE', message: /mode/ }
);
await access(dest);
const handle = await open(dest, 'r+');
await handle.datasync();
await handle.sync();
const buf = Buffer.from('hello world');
await handle.write(buf);
const ret = await handle.read(Buffer.alloc(11), 0, 11, 0);
assert.strictEqual(ret.bytesRead, 11);
assert.deepStrictEqual(ret.buffer, buf);
await handle.close();
}
validate();