deno.land / std@0.166.0 / node / _fs / _fs_stat.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.import { denoErrorToNodeError } from "../internal/errors.ts";import { promisify } from "../internal/util.mjs";
export type statOptions = { bigint: boolean; throwIfNoEntry?: boolean;};
export type Stats = { /** ID of the device containing the file. * * _Linux/Mac OS only._ */ dev: number | null; /** Inode number. * * _Linux/Mac OS only._ */ ino: number | null; /** **UNSTABLE**: Match behavior with Go on Windows for `mode`. * * The underlying raw `st_mode` bits that contain the standard Unix * permissions for this file/directory. */ mode: number | null; /** Number of hard links pointing to this file. * * _Linux/Mac OS only._ */ nlink: number | null; /** User ID of the owner of this file. * * _Linux/Mac OS only._ */ uid: number | null; /** Group ID of the owner of this file. * * _Linux/Mac OS only._ */ gid: number | null; /** Device ID of this file. * * _Linux/Mac OS only._ */ rdev: number | null; /** The size of the file, in bytes. */ size: number; /** Blocksize for filesystem I/O. * * _Linux/Mac OS only._ */ blksize: number | null; /** Number of blocks allocated to the file, in 512-byte units. * * _Linux/Mac OS only._ */ blocks: number | null; /** The last modification time of the file. This corresponds to the `mtime` * field from `stat` on Linux/Mac OS and `ftLastWriteTime` on Windows. This * may not be available on all platforms. */ mtime: Date | null; /** The last access time of the file. This corresponds to the `atime` * field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not * be available on all platforms. */ atime: Date | null; /** The creation time of the file. This corresponds to the `birthtime` * field from `stat` on Mac/BSD and `ftCreationTime` on Windows. This may * not be available on all platforms. */ birthtime: Date | null; /** change time */ ctime: Date | null; /** atime in milliseconds */ atimeMs: number | null; /** atime in milliseconds */ mtimeMs: number | null; /** atime in milliseconds */ ctimeMs: number | null; /** atime in milliseconds */ birthtimeMs: number | null; isBlockDevice: () => boolean; isCharacterDevice: () => boolean; isDirectory: () => boolean; isFIFO: () => boolean; isFile: () => boolean; isSocket: () => boolean; isSymbolicLink: () => boolean;};
export type BigIntStats = { /** ID of the device containing the file. * * _Linux/Mac OS only._ */ dev: BigInt | null; /** Inode number. * * _Linux/Mac OS only._ */ ino: BigInt | null; /** **UNSTABLE**: Match behavior with Go on Windows for `mode`. * * The underlying raw `st_mode` bits that contain the standard Unix * permissions for this file/directory. */ mode: BigInt | null; /** Number of hard links pointing to this file. * * _Linux/Mac OS only._ */ nlink: BigInt | null; /** User ID of the owner of this file. * * _Linux/Mac OS only._ */ uid: BigInt | null; /** Group ID of the owner of this file. * * _Linux/Mac OS only._ */ gid: BigInt | null; /** Device ID of this file. * * _Linux/Mac OS only._ */ rdev: BigInt | null; /** The size of the file, in bytes. */ size: BigInt; /** Blocksize for filesystem I/O. * * _Linux/Mac OS only._ */ blksize: BigInt | null; /** Number of blocks allocated to the file, in 512-byte units. * * _Linux/Mac OS only._ */ blocks: BigInt | null; /** The last modification time of the file. This corresponds to the `mtime` * field from `stat` on Linux/Mac OS and `ftLastWriteTime` on Windows. This * may not be available on all platforms. */ mtime: Date | null; /** The last access time of the file. This corresponds to the `atime` * field from `stat` on Unix and `ftLastAccessTime` on Windows. This may not * be available on all platforms. */ atime: Date | null; /** The creation time of the file. This corresponds to the `birthtime` * field from `stat` on Mac/BSD and `ftCreationTime` on Windows. This may * not be available on all platforms. */ birthtime: Date | null; /** change time */ ctime: Date | null; /** atime in milliseconds */ atimeMs: BigInt | null; /** atime in milliseconds */ mtimeMs: BigInt | null; /** atime in milliseconds */ ctimeMs: BigInt | null; /** atime in nanoseconds */ birthtimeMs: BigInt | null; /** atime in nanoseconds */ atimeNs: BigInt | null; /** atime in nanoseconds */ mtimeNs: BigInt | null; /** atime in nanoseconds */ ctimeNs: BigInt | null; /** atime in nanoseconds */ birthtimeNs: BigInt | null; isBlockDevice: () => boolean; isCharacterDevice: () => boolean; isDirectory: () => boolean; isFIFO: () => boolean; isFile: () => boolean; isSocket: () => boolean; isSymbolicLink: () => boolean;};
export function convertFileInfoToStats(origin: Deno.FileInfo): Stats { return { dev: origin.dev, ino: origin.ino, mode: origin.mode, nlink: origin.nlink, uid: origin.uid, gid: origin.gid, rdev: origin.rdev, size: origin.size, blksize: origin.blksize, blocks: origin.blocks, mtime: origin.mtime, atime: origin.atime, birthtime: origin.birthtime, mtimeMs: origin.mtime?.getTime() || null, atimeMs: origin.atime?.getTime() || null, birthtimeMs: origin.birthtime?.getTime() || null, isFile: () => origin.isFile, isDirectory: () => origin.isDirectory, isSymbolicLink: () => origin.isSymlink, // not sure about those isBlockDevice: () => false, isFIFO: () => false, isCharacterDevice: () => false, isSocket: () => false, ctime: origin.mtime, ctimeMs: origin.mtime?.getTime() || null, };}
function toBigInt(number?: number | null) { if (number === null || number === undefined) return null; return BigInt(number);}
export function convertFileInfoToBigIntStats( origin: Deno.FileInfo,): BigIntStats { return { dev: toBigInt(origin.dev), ino: toBigInt(origin.ino), mode: toBigInt(origin.mode), nlink: toBigInt(origin.nlink), uid: toBigInt(origin.uid), gid: toBigInt(origin.gid), rdev: toBigInt(origin.rdev), size: toBigInt(origin.size) || 0n, blksize: toBigInt(origin.blksize), blocks: toBigInt(origin.blocks), mtime: origin.mtime, atime: origin.atime, birthtime: origin.birthtime, mtimeMs: origin.mtime ? BigInt(origin.mtime.getTime()) : null, atimeMs: origin.atime ? BigInt(origin.atime.getTime()) : null, birthtimeMs: origin.birthtime ? BigInt(origin.birthtime.getTime()) : null, mtimeNs: origin.mtime ? BigInt(origin.mtime.getTime()) * 1000000n : null, atimeNs: origin.atime ? BigInt(origin.atime.getTime()) * 1000000n : null, birthtimeNs: origin.birthtime ? BigInt(origin.birthtime.getTime()) * 1000000n : null, isFile: () => origin.isFile, isDirectory: () => origin.isDirectory, isSymbolicLink: () => origin.isSymlink, // not sure about those isBlockDevice: () => false, isFIFO: () => false, isCharacterDevice: () => false, isSocket: () => false, ctime: origin.mtime, ctimeMs: origin.mtime ? BigInt(origin.mtime.getTime()) : null, ctimeNs: origin.mtime ? BigInt(origin.mtime.getTime()) * 1000000n : null, };}
// shortcut for Convert File Info to Stats or BigIntStatsexport function CFISBIS(fileInfo: Deno.FileInfo, bigInt: boolean) { if (bigInt) return convertFileInfoToBigIntStats(fileInfo); return convertFileInfoToStats(fileInfo);}
export type statCallbackBigInt = (err: Error | null, stat: BigIntStats) => void;
export type statCallback = (err: Error | null, stat: Stats) => void;
export function stat(path: string | URL, callback: statCallback): void;export function stat( path: string | URL, options: { bigint: false }, callback: statCallback,): void;export function stat( path: string | URL, options: { bigint: true }, callback: statCallbackBigInt,): void;export function stat( path: string | URL, optionsOrCallback: statCallback | statCallbackBigInt | statOptions, maybeCallback?: statCallback | statCallbackBigInt,) { const callback = (typeof optionsOrCallback === "function" ? optionsOrCallback : maybeCallback) as ( ...args: [Error] | [null, BigIntStats | Stats] ) => void; const options = typeof optionsOrCallback === "object" ? optionsOrCallback : { bigint: false };
if (!callback) throw new Error("No callback function supplied");
Deno.stat(path).then( (stat) => callback(null, CFISBIS(stat, options.bigint)), (err) => callback(denoErrorToNodeError(err, { syscall: "stat" })), );}
export const statPromise = promisify(stat) as ( & ((path: string | URL) => Promise<Stats>) & ((path: string | URL, options: { bigint: false }) => Promise<Stats>) & ((path: string | URL, options: { bigint: true }) => Promise<BigIntStats>));
export function statSync(path: string | URL): Stats;export function statSync( path: string | URL, options: { bigint: false; throwIfNoEntry?: boolean },): Stats;export function statSync( path: string | URL, options: { bigint: true; throwIfNoEntry?: boolean },): BigIntStats;export function statSync( path: string | URL, options: statOptions = { bigint: false, throwIfNoEntry: true },): Stats | BigIntStats | undefined { try { const origin = Deno.statSync(path); return CFISBIS(origin, options.bigint); } catch (err) { if ( options?.throwIfNoEntry === false && err instanceof Deno.errors.NotFound ) { return; } if (err instanceof Error) { throw denoErrorToNodeError(err, { syscall: "stat" }); } else { throw err; } }}
std

Version Info

Tagged at
a year ago