2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-06-04 19:09:29 -04:00
|
|
|
|
2023-03-19 12:10:39 -04:00
|
|
|
import { fstat, fstatSync } from "node:fs";
|
2024-02-12 21:05:10 -05:00
|
|
|
import { fail } from "@std/assert/mod.ts";
|
2023-03-19 12:10:39 -04:00
|
|
|
import { assertStats, assertStatsBigInt } from "./_fs_stat_test.ts";
|
|
|
|
import type { BigIntStats, Stats } from "node:fs";
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "ASYNC: get a file Stats",
|
|
|
|
async fn() {
|
2024-01-24 09:59:55 -05:00
|
|
|
const filePath = await Deno.makeTempFile();
|
|
|
|
using file = await Deno.open(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
|
|
|
|
await new Promise<Stats>((resolve, reject) => {
|
2024-01-24 09:59:55 -05:00
|
|
|
fstat(file.rid, (err: Error | null, stat: Stats) => {
|
2023-03-19 12:10:39 -04:00
|
|
|
if (err) reject(err);
|
|
|
|
resolve(stat);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(
|
|
|
|
(stat) => {
|
2024-01-24 12:53:20 -05:00
|
|
|
assertStats(stat, file.statSync());
|
2023-03-19 12:10:39 -04:00
|
|
|
},
|
|
|
|
() => fail(),
|
|
|
|
)
|
|
|
|
.finally(() => {
|
2024-01-24 09:59:55 -05:00
|
|
|
Deno.removeSync(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "ASYNC: get a file BigInt Stats",
|
|
|
|
async fn() {
|
2024-01-24 09:59:55 -05:00
|
|
|
const filePath = await Deno.makeTempFile();
|
|
|
|
using file = await Deno.open(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
|
|
|
|
await new Promise<BigIntStats>((resolve, reject) => {
|
2024-01-24 09:59:55 -05:00
|
|
|
fstat(
|
|
|
|
file.rid,
|
|
|
|
{ bigint: true },
|
|
|
|
(err: Error | null, stat: BigIntStats) => {
|
|
|
|
if (err) reject(err);
|
|
|
|
resolve(stat);
|
|
|
|
},
|
|
|
|
);
|
2023-03-19 12:10:39 -04:00
|
|
|
})
|
|
|
|
.then(
|
2024-01-24 12:53:20 -05:00
|
|
|
(stat) => assertStatsBigInt(stat, file.statSync()),
|
2023-03-19 12:10:39 -04:00
|
|
|
() => fail(),
|
|
|
|
)
|
|
|
|
.finally(() => {
|
2024-01-24 09:59:55 -05:00
|
|
|
Deno.removeSync(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "SYNC: get a file Stats",
|
|
|
|
fn() {
|
2024-01-24 09:59:55 -05:00
|
|
|
const filePath = Deno.makeTempFileSync();
|
|
|
|
using file = Deno.openSync(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
|
|
|
|
try {
|
2024-01-24 12:53:20 -05:00
|
|
|
assertStats(fstatSync(file.rid), file.statSync());
|
2023-03-19 12:10:39 -04:00
|
|
|
} finally {
|
2024-01-24 09:59:55 -05:00
|
|
|
Deno.removeSync(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "SYNC: get a file BigInt Stats",
|
|
|
|
fn() {
|
2024-01-24 09:59:55 -05:00
|
|
|
const filePath = Deno.makeTempFileSync();
|
|
|
|
using file = Deno.openSync(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
|
|
|
|
try {
|
2024-01-24 12:53:20 -05:00
|
|
|
// HEAD
|
|
|
|
assertStatsBigInt(fstatSync(file.rid, { bigint: true }), file.statSync());
|
|
|
|
//
|
2024-01-24 09:59:55 -05:00
|
|
|
assertStatsBigInt(
|
|
|
|
fstatSync(file.rid, { bigint: true }),
|
2024-06-17 18:40:05 -04:00
|
|
|
file.statSync(),
|
2024-01-24 09:59:55 -05:00
|
|
|
);
|
2024-01-24 12:53:20 -05:00
|
|
|
//main
|
2023-03-19 12:10:39 -04:00
|
|
|
} finally {
|
2024-01-24 09:59:55 -05:00
|
|
|
Deno.removeSync(filePath);
|
2023-03-19 12:10:39 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|