Mô-đun
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
4 cho phép tương tác với hệ thống tệp theo cách được mô hình hóa trên các chức năng POSIX tiêu chuẩnĐể sử dụng các API dựa trên lời hứa
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Để sử dụng API gọi lại và đồng bộ hóa
import * as fs from 'node:fs';
const fs = require['node:fs'];
Tất cả các hoạt động của hệ thống tệp đều có biểu mẫu đồng bộ, gọi lại và dựa trên lời hứa và có thể truy cập bằng cả cú pháp CommonJS và Mô-đun ES6 [ESM]
Ví dụ về lời hứa
Các hoạt động dựa trên lời hứa trả về một lời hứa được thực hiện khi hoạt động không đồng bộ hoàn tất
import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
ví dụ gọi lại
Biểu mẫu gọi lại lấy hàm gọi lại hoàn thành làm đối số cuối cùng của nó và gọi hoạt động không đồng bộ. Các đối số được truyền cho lệnh gọi lại hoàn thành phụ thuộc vào phương thức, nhưng đối số đầu tiên luôn được dành riêng cho một ngoại lệ. Nếu thao tác hoàn tất thành công, thì đối số đầu tiên là
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
5 hoặc import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Các phiên bản dựa trên gọi lại của API mô-đun
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
4 được ưu tiên sử dụng hơn so với việc sử dụng các API hứa hẹn khi hiệu suất tối đa [cả về thời gian thực hiện và cấp phát bộ nhớ] là bắt buộcví dụ đồng bộ
Các API đồng bộ chặn Nút. js và thực thi JavaScript tiếp theo cho đến khi thao tác hoàn tất. Các ngoại lệ được đưa ra ngay lập tức và có thể được xử lý bằng cách sử dụng
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
8 hoặc có thể được phép nổi lênAPI lời hứa
Lịch sửPhiên bảnChangesv14. 0. 0
tiếp xúc như
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
9v11. 14. 0, v10. 17. 0API này không còn thử nghiệm nữa
v10. 1. 0Chỉ có thể truy cập API qua
00v10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
API
01 cung cấp các phương thức hệ thống tệp không đồng bộ trả về lời hứaimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Các API lời hứa sử dụng Nút bên dưới. js để thực hiện các hoạt động của hệ thống tệp ngoài luồng vòng lặp sự kiện. Các hoạt động này không được đồng bộ hóa hoặc luồng an toàn. Phải cẩn thận khi thực hiện nhiều sửa đổi đồng thời trên cùng một tệp, nếu không có thể xảy ra lỗi dữ liệu
Lớp. import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
02
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Một đối tượng là một trình bao bọc đối tượng cho một bộ mô tả tệp số
Thể hiện của đối tượng được tạo bằng phương thức
03import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tất cả các đối tượng là s
Nếu a không được đóng bằng phương pháp
04, nó sẽ cố gắng tự động đóng bộ mô tả tệp và đưa ra cảnh báo quy trình, giúp ngăn rò rỉ bộ nhớ. Vui lòng không dựa vào hành vi này vì nó có thể không đáng tin cậy và tệp có thể không được đóng. Thay vào đó, luôn luôn đóng s một cách rõ ràng. Nút. js có thể thay đổi hành vi này trong tương laiBiến cố.import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
05import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Sự kiện
05 được phát ra khi đã đóng và không thể sử dụng được nữaimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
07import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Lịch sửPhiên bảnThay đổiv15. 14. 0, v14. 18. 0
Đối số
08 hỗ trợimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
08 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
Bí danh của
Khi thao tác trên các bộ điều khiển tệp, không thể thay đổi chế độ so với chế độ đã đặt với. Do đó, điều này tương đương với
06import * as fs from 'node:fs';
const fs = require['node:fs'];
Sửa đổi các quyền trên tệp. Xem
07import * as fs from 'node:fs';
const fs = require['node:fs'];
08import * as fs from 'node:fs';
const fs = require['node:fs'];
09 Id người dùng của chủ sở hữu mới của tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
70 Id nhóm của nhóm mới của tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Thay đổi quyền sở hữu của tập tin. Một trình bao bọc cho
72import * as fs from 'node:fs';
const fs = require['node:fs'];
04import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đóng bộ điều khiển tệp sau khi đợi bất kỳ thao tác đang chờ xử lý nào trên bộ điều khiển hoàn tất
2import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
75import * as fs from 'node:fs';
const fs = require['node:fs'];
Không giống như 16 KiB mặc định
76 cho a , luồng được phương pháp này trả về có mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
76 mặc định là 64 KiBimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 có thể bao gồm các giá trịimport * as fs from 'node:fs';
const fs = require['node:fs'];
79 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
80 để đọc một phạm vi byte từ tệp thay vì toàn bộ tệp. Cảimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
79 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
80 đều bao gồm và bắt đầu đếm từ 0, các giá trị được phép nằm trong phạm vi [0,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
83]. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
79 bị bỏ qua hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6, thì 86 sẽ đọc tuần tự từ vị trí tệp hiện tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 có thể là bất kỳ một trong số đó được chấp nhận bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
02 trỏ đến một thiết bị ký tự chỉ hỗ trợ chặn đọc [chẳng hạn như bàn phím hoặc card âm thanh], thì thao tác đọc sẽ không kết thúc cho đến khi có dữ liệu. Điều này có thể ngăn quá trình thoát và luồng đóng tự nhiênimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Theo mặc định, luồng sẽ phát ra sự kiện
05 sau khi nó bị hủy. Đặt tùy chọnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 để thay đổi hành vi nàyimport * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu
02 là sai, thì bộ mô tả tệp sẽ không bị đóng, ngay cả khi có lỗi. Ứng dụng có trách nhiệm đóng nó và đảm bảo không có rò rỉ bộ mô tả tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 được đặt thành true [hành vi mặc định], trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
05, bộ mô tả tệp sẽ tự động bị đóngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Một ví dụ để đọc 10 byte cuối cùng của tệp dài 100 byte
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
06import * as fs from 'node:fs';
const fs = require['node:fs'];
78 cũng có thể bao gồm tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
79 để cho phép ghi dữ liệu ở một số vị trí sau phần đầu của tệp, các giá trị được phép nằm trong phạm vi [0,import * as fs from 'node:fs';
const fs = require['node:fs'];
83]. Sửa đổi một tệp thay vì thay thế nó có thể yêu cầu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10import * as fs from 'node:fs';
const fs = require['node:fs'];
11 được đặt thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
12 thay vì mặc định làimport * as fs from 'node:fs';
const fs = require['node:fs'];
13.import * as fs from 'node:fs';
const fs = require['node:fs'];
87 có thể là bất kỳ một trong số đó được chấp nhận bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
02 được đặt thành true [hành vi mặc định] trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
17, bộ mô tả tệp sẽ tự động bị đóng. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 là sai, thì bộ mô tả tệp sẽ không bị đóng, ngay cả khi có lỗi. Ứng dụng có trách nhiệm đóng nó và đảm bảo không có rò rỉ bộ mô tả tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Theo mặc định, luồng sẽ phát ra sự kiện
05 sau khi nó bị hủy. Đặt tùy chọnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 để thay đổi hành vi nàyimport * as fs from 'node:fs';
const fs = require['node:fs'];
22import * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Buộc tất cả các hoạt động I/O được xếp hàng hiện tại được liên kết với tệp về trạng thái hoàn thành I/O được đồng bộ hóa của hệ điều hành. Tham khảo tài liệu POSIX
24 để biết chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Không giống như
25, phương pháp này không xóa siêu dữ liệu đã sửa đổiimport * as fs from 'node:fs';
const fs = require['node:fs'];
26import * as fs from 'node:fs';
const fs = require['node:fs'];
27import * as fs from 'node:fs';
const fs = require['node:fs'];
28. . Một bộ đệm sẽ chứa đầy dữ liệu tệp đã đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
29 Vị trí trong bộ đệm để bắt đầu điềnimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số byte cần đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
31. Vị trí bắt đầu đọc dữ liệu từ tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
5, dữ liệu sẽ được đọc từ vị trí tệp hiện tại và vị trí sẽ được cập nhật. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
31 là số nguyên, vị trí tệp hiện tại sẽ không thay đổiimport * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành khi thành công với một đối tượng có hai thuộc tính
Đọc dữ liệu từ tệp và lưu trữ dữ liệu đó trong bộ đệm đã cho
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
34import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v13. 11. 0, v12. 17. 0
78import * as fs from 'node:fs';
const fs = require['node:fs'];
28. . Một bộ đệm sẽ chứa đầy dữ liệu tệp đã đọc. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
37import * as fs from 'node:fs';
const fs = require['node:fs'];
29 Vị trí trong bộ đệm để bắt đầu điền. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số byte cần đọc. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
41import * as fs from 'node:fs';
const fs = require['node:fs'];
31. Vị trí bắt đầu đọc dữ liệu từ tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
5, dữ liệu sẽ được đọc từ vị trí tệp hiện tại và vị trí sẽ được cập nhật. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
31 là số nguyên, vị trí tệp hiện tại sẽ không thay đổi. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. Hoàn thành khi thành công với một đối tượng có hai thuộc tính
Đọc dữ liệu từ tệp và lưu trữ dữ liệu đó trong bộ đệm đã cho
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
46import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v18. 2. 0, v16. 17. 0
28. . Một bộ đệm sẽ chứa đầy dữ liệu tệp đã đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
29 Vị trí trong bộ đệm để bắt đầu điền. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số byte cần đọc. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
41import * as fs from 'node:fs';
const fs = require['node:fs'];
31 Vị trí bắt đầu đọc dữ liệu từ tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
5, dữ liệu sẽ được đọc từ vị trí tệp hiện tại và vị trí sẽ được cập nhật. Nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
31 là số nguyên, vị trí tệp hiện tại sẽ không thay đổi. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. Hoàn thành khi thành công với một đối tượng có hai thuộc tính
Đọc dữ liệu từ tệp và lưu trữ dữ liệu đó trong bộ đệm đã cho
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
57import * as fs from 'node:fs';
const fs = require['node:fs'];
Trả về một
58 có thể được sử dụng để đọc dữ liệu tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sẽ xảy ra lỗi nếu phương thức này được gọi nhiều lần hoặc được gọi sau khi đóng hoặc đóng
02import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Mặc dù
58 sẽ đọc tệp cho đến khi hoàn thành, nhưng nó sẽ không tự động đóngimport * as fs from 'node:fs';
const fs = require['node:fs'];
02. Mã người dùng vẫn phải gọi phương thứcimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
62import * as fs from 'node:fs';
const fs = require['node:fs'];
63import * as fs from 'node:fs';
const fs = require['node:fs'];
78.import * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành khi đọc thành công với nội dung của tệp. Nếu không chỉ định mã hóa [sử dụng
65], dữ liệu được trả về dưới dạng đối tượng. Nếu không, dữ liệu sẽ là một chuỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Đọc không đồng bộ toàn bộ nội dung của một tệp
Nếu
78 là một chuỗi, thì nó chỉ địnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phải hỗ trợ đọc
Nếu một hoặc nhiều lệnh gọi
68 được thực hiện trên một bộ xử lý tệp và sau đó một lệnh gọiimport * as fs from 'node:fs';
const fs = require['node:fs'];
69 được thực hiện, dữ liệu sẽ được đọc từ vị trí hiện tại cho đến hết tệp. Không phải lúc nào nó cũng đọc từ đầu tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
70import * as fs from 'node:fs';
const fs = require['node:fs'];
Phương pháp tiện lợi để tạo giao diện
71 và truyền phát qua tệp. Xem các tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
0import * as fs from 'node:fs';
const fs = require['node:fs'];
73import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v13. 13. 0, v12. 17. 0
74. .import * as fs from 'node:fs';
const fs = require['node:fs'];
31. Phần bù từ đầu tệp nơi dữ liệu sẽ được đọc từ đó. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 không phải làimport * as fs from 'node:fs';
const fs = require['node:fs'];
77, dữ liệu sẽ được đọc từ vị trí hiện tại. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. Hoàn thành khi thành công một đối tượng chứa hai thuộc tính
Đọc từ một tệp và ghi vào một mảng s
79import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv10. 5. 0
Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v10. 0. 0
81import * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Yêu cầu tất cả dữ liệu cho bộ mô tả tệp mở được chuyển sang thiết bị lưu trữ. Việc triển khai cụ thể là hệ điều hành và thiết bị cụ thể. Tham khảo tài liệu POSIX
83 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
84import * as fs from 'node:fs';
const fs = require['node:fs'];
Cắt bớt tập tin
Nếu tệp lớn hơn
85 byte, thì chỉimport * as fs from 'node:fs';
const fs = require['node:fs'];
85 byte đầu tiên sẽ được giữ lại trong tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Ví dụ sau chỉ giữ lại bốn byte đầu tiên của tệp
7import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu tệp trước đó ngắn hơn
85 byte, nó sẽ được mở rộng và phần mở rộng chứa đầy byte rỗng [import * as fs from 'node:fs';
const fs = require['node:fs'];
88]import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu
85 âm thì sẽ sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
91import * as fs from 'node:fs';
const fs = require['node:fs'];
Thay đổi dấu thời gian hệ thống tệp của đối tượng được tham chiếu sau đó giải quyết lời hứa mà không có đối số khi thành công
92import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv14. 0. 0
Tham số
28 sẽ không ép buộc đầu vào không được hỗ trợ vào bộ đệm nữav10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v10. 0. 0
28. .import * as fs from 'node:fs';
const fs = require['node:fs'];
29 Vị trí bắt đầu từ bên trongimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 nơi bắt đầu ghi dữ liệuimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số lượng byte từimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 để ghi. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
41import * as fs from 'node:fs';
const fs = require['node:fs'];
31. Phần bù từ đầu tệp nơi dữ liệu từimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 sẽ được ghi. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 không phải làimport * as fs from 'node:fs';
const fs = require['node:fs'];
77, dữ liệu sẽ được ghi ở vị trí hiện tại. Xem tài liệu POSIXimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 để biết thêm chi tiết. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại.
Viết
28 vào tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Lời hứa được giải quyết với một đối tượng chứa hai thuộc tính
Sẽ không an toàn khi sử dụng
07 nhiều lần trên cùng một tệp mà không đợi lời hứa được giải quyết [hoặc bị từ chối]. Đối với kịch bản này, sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
09import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v18. 3. 0, v16. 17. 0
Viết
28 vào tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Tương tự như hàm
11 ở trên, phiên bản này có một đối tượngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78 tùy chọn. Nếu không có đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 nào được chỉ định, nó sẽ mặc định với các giá trị trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
14import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
Tham số
15 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
15import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31. Phần bù từ đầu tệp nơi dữ liệu từimport * as fs from 'node:fs';
const fs = require['node:fs'];
15 sẽ được ghi. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 không phải làimport * as fs from 'node:fs';
const fs = require['node:fs'];
77, dữ liệu sẽ được ghi ở vị trí hiện tại. Xem tài liệu POSIXimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 để biết thêm chi tiết. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
87 Mã hóa chuỗi dự kiến. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
24import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- trả lại.
Viết
15 vào tệp. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
15 không phải là một chuỗi, thì lời hứa bị từ chối kèm theo lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lời hứa được giải quyết với một đối tượng chứa hai thuộc tính
27 số byte được ghiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28 một tham chiếu đếnimport * as fs from 'node:fs';
const fs = require['node:fs'];
15 bằng văn bảnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Sẽ không an toàn khi sử dụng
07 nhiều lần trên cùng một tệp mà không đợi lời hứa được giải quyết [hoặc bị từ chối]. Đối với kịch bản này, sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
32import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv15. 14. 0, v14. 18. 0
Đối số
08 hỗ trợimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
08 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
Ghi dữ liệu vào tệp không đồng bộ, thay thế tệp nếu tệp đã tồn tại.
08 có thể là một chuỗi, một bộ đệm, một hoặc một đối tượng. Lời hứa được giải quyết mà không có tranh luận khi thành côngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Nếu
78 là một chuỗi, thì nó chỉ địnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phải hỗ trợ viết
Sẽ không an toàn khi sử dụng
03 nhiều lần trên cùng một tệp mà không đợi lời hứa được giải quyết [hoặc bị từ chối]import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu một hoặc nhiều lệnh gọi
07 được thực hiện trên một bộ xử lý tệp và sau đó một lệnh gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 được thực hiện, dữ liệu sẽ được ghi từ vị trí hiện tại cho đến hết tệp. Không phải lúc nào nó cũng ghi từ đầu tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
44import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Viết một mảng s vào tệp
Lời hứa được giải quyết với một đối tượng chứa hai thuộc tính
Sẽ không an toàn khi gọi
45 nhiều lần trên cùng một tệp mà không đợi lời hứa được giải quyết [hoặc bị từ chối]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
46
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Kiểm tra quyền của người dùng đối với tệp hoặc thư mục được chỉ định bởi
47. Đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 là một số nguyên tùy chọn chỉ định kiểm tra khả năng truy cập sẽ được thực hiện.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 phải là giá trịimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
50 hoặc mặt nạ bao gồm bitwise OR của bất kỳ giá trị nào trong sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
51,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
52 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
54]. Kiểm tra các giá trị có thể có củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu kiểm tra khả năng truy cập thành công, lời hứa sẽ được giải quyết mà không có giá trị. Nếu bất kỳ kiểm tra khả năng truy cập nào không thành công, lời hứa sẽ bị từ chối với một đối tượng. Ví dụ sau kiểm tra xem tệp
56 có thể được đọc và ghi bởi quy trình hiện tại khôngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
8import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Không nên sử dụng
57 để kiểm tra khả năng truy cập tệp trước khi gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03. Làm như vậy sẽ đưa ra một điều kiện cạnh tranh, vì các quy trình khác có thể thay đổi trạng thái của tệp giữa hai lần gọi. Thay vào đó, mã người dùng nên trực tiếp mở/đọc/ghi tệp và xử lý lỗi phát sinh nếu tệp không thể truy cập đượcimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
59
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Nối dữ liệu vào một tệp không đồng bộ, tạo tệp nếu nó chưa tồn tại.
08 có thể là một chuỗi hoặc mộtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Nếu
78 là một chuỗi, thì nó chỉ địnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tùy chọn
48 chỉ ảnh hưởng đến tệp mới tạo. Xem để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 có thể được chỉ định là một đã được mở để nối thêm [sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03]import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
67
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Thay đổi quyền của một tập tin
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
68
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Thay đổi quyền sở hữu của một tập tin
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
69
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
Đã thay đổi đối số
10 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 và áp đặt xác thực loại nghiêm ngặt hơnv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
72. . tên tệp nguồn để sao chépimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. . tên tệp đích của thao tác sao chépimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 Công cụ sửa đổi tùy chọn chỉ định hành vi của thao tác sao chép. Có thể tạo một mặt nạ bao gồm OR theo bit của hai hoặc nhiều giá trị [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
75] Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
77. Thao tác sao chép sẽ thất bại nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73 đã tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
79. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì cơ chế sao chép dự phòng sẽ được sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
80. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành côngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Sao chép không đồng bộ
72 sangimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. Theo mặc định,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73 được ghi đè nếu nó đã tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Không có đảm bảo nào về tính nguyên tử của hoạt động sao chép. Nếu xảy ra lỗi sau khi tệp đích đã được mở để ghi, một nỗ lực sẽ được thực hiện để xóa đích
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
85
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv17. 6. 0, v16. 15. 0
Chấp nhận tùy chọn
86 bổ sung để chỉ định có thực hiện phân giải đường dẫn cho liên kết tượng trưng hay khôngv16. 7. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v16. 7. 0
72. đường dẫn nguồn để sao chépimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. đường dẫn đích để sao chép vàoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
90 liên kết tượng trưng dereference. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
92 khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
93 làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 và đích tồn tại, đưa ra lỗi. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
96 Chức năng lọc tập tin/thư mục sao chép. Trả lạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97 để sao chép mục này,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 để bỏ qua nó. Cũng có thể trả về mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
99 phân giải thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
93 ghi đè lên tệp hoặc thư mục hiện có. Thao tác sao chép sẽ bỏ qua lỗi nếu bạn đặt giá trị này thành false và đích tồn tại. Sử dụng tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
92 để thay đổi hành vi này. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 Khi dấu thời gian củaimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97 từimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
72 sẽ được giữ nguyên. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
10 sao chép thư mục theo cách đệ quy Mặc định.import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
86 Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97, độ phân giải đường dẫn cho các liên kết tượng trưng sẽ bị bỏ qua. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Sao chép không đồng bộ toàn bộ cấu trúc thư mục từ
72 đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73, bao gồm các thư mục con và tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Khi sao chép một thư mục sang một thư mục khác, khối cầu không được hỗ trợ và hành vi tương tự như
18import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
19
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Không dùng nữa kể từ. v10. 0. 0
Thay đổi quyền trên một liên kết tượng trưng
Phương pháp này chỉ được thực hiện trên macOS
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
20
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnChangesv10. 6. 0
API này không còn được dùng nữa
v10. 0. 0Đã thêm vào. v10. 0. 0
Thay đổi quyền sở hữu trên một liên kết tượng trưng
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
21
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Đã thêm vào. v14. 5. 0, v12. 19. 0
Thay đổi thời gian truy cập và sửa đổi của một tệp giống như cách thay đổi, với điểm khác biệt là nếu đường dẫn đề cập đến một liên kết tượng trưng, thì liên kết đó không được hủy đăng ký. thay vào đó, dấu thời gian của chính liên kết tượng trưng được thay đổi
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
23
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Tạo một liên kết mới từ ________ 624 đến ________ 625. Xem tài liệu POSIX
26 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
27
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnThay đổiv10. 5. 0
Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v10. 0. 0
Tương đương với trừ khi
47 đề cập đến một liên kết tượng trưng, trong trường hợp đó, chính liên kết đó đã được thống kê, không phải tệp mà nó đề cập đến. Tham khảo tài liệu POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
32
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Tạo thư mục không đồng bộ
Đối số
78 tùy chọn có thể là một số nguyên chỉ địnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 [các bit quyền và dính] hoặc một đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 và thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 cho biết có nên tạo thư mục mẹ hay không. Gọiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
37 khiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
47 là một thư mục tồn tại dẫn đến từ chối chỉ khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 là saiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
0import * as fs from 'node:fs';
const fs = require['node:fs'];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
40
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnThay đổiv16. 5. 0, v14. 18. 0
Tham số
41 hiện chấp nhận một chuỗi rỗngv10. 0. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v10. 0. 0
Tạo một thư mục tạm thời duy nhất. Một tên thư mục duy nhất được tạo bằng cách thêm sáu ký tự ngẫu nhiên vào cuối
41 được cung cấp. Do sự không nhất quán của nền tảng, hãy tránh sử dụng các ký tựimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
43 trongimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
41. Một số nền tảng, đặc biệt là BSD, có thể trả về nhiều hơn sáu ký tự ngẫu nhiên và thay thế các ký tựimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
43 ở cuối trongimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
41 bằng các ký tự ngẫu nhiênimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
1import * as fs from 'node:fs';
const fs = require['node:fs'];
Phương thức
49 sẽ nối trực tiếp sáu ký tự được chọn ngẫu nhiên vào chuỗiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
41. Ví dụ: được cung cấp một thư mụcimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
51, nếu mục đích là tạo một thư mục tạm thời trongimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
51, thì ____641 phải kết thúc bằng dấu phân cách đường dẫn dành riêng cho nền tảng [import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
54]import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
55
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnChangesv11. 1. 0
Đối số
10 hiện là tùy chọn và mặc định làimport * as fs from 'node:fs';
const fs = require['node:fs'];
57v10. 0. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v10. 0. 0
mở một
Tham khảo tài liệu POSIX
58 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Một số ký tự [
59] được dành riêng trong Windows như được ghi lại bằng cách đặt tên tệp, đường dẫn và không gian tên. Trong NTFS, nếu tên tệp chứa dấu hai chấm, Nút. js sẽ mở một luồng hệ thống tệp, như được mô tả bởi this MSDN pageimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
60
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnThay đổiv13. 1. 0, v12. 16. 0
Tùy chọn
61 đã được giới thiệuv12. 12. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v12. 12. 0
Mở thư mục không đồng bộ để quét lặp lại. Xem tài liệu POSIX
62 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tạo một , chứa tất cả các chức năng khác để đọc và dọn dẹp thư mục
Tùy chọn
87 đặt mã hóa choimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 trong khi mở thư mục và các thao tác đọc tiếp theoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ví dụ sử dụng phép lặp không đồng bộ
2import * as fs from 'node:fs';
const fs = require['node:fs'];
Khi sử dụng async iterator, đối tượng sẽ tự động đóng sau khi iterator thoát
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
65
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnThay đổiv10. 11. 0
Tùy chọn mới
66 đã được thêm vàov10. 0. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v10. 0. 0
Đọc nội dung của một thư mục
Đối số tùy chọn
78 có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho tên tệp. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, tên tệp được trả về sẽ được chuyển dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Nếu
71 được đặt thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, mảng đã phân giải sẽ chứa các đối tượngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
3import * as fs from 'node:fs';
const fs = require['node:fs'];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
73
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Lịch sửPhiên bảnThay đổiv15. 2. 0, v14. 17. 0
Đối số tùy chọn có thể bao gồm AbortSignal để hủy bỏ yêu cầu readFile đang diễn ra
v10. 0. 0Đã thêm vào. v10. 0. 0
Đọc không đồng bộ toàn bộ nội dung của một tệp
Nếu không chỉ định mã hóa [sử dụng
65], dữ liệu được trả về dưới dạng đối tượng. Nếu không, dữ liệu sẽ là một chuỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
Khi
47 là một thư mục, hành vi củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
77 là dành riêng cho nền tảng. Trên macOS, Linux và Windows, lời hứa sẽ bị từ chối do lỗi. Trên FreeBSD, nội dung của thư mục sẽ được trả vềimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Một ví dụ về đọc tệp
78 nằm trong cùng thư mục của mã đang chạyimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
4import * as fs from 'node:fs';
const fs = require['node:fs'];
Có thể hủy bỏ một
79 đang diễn ra bằng cách sử dụng một. Nếu một yêu cầu bị hủy bỏ, lời hứa được trả lại sẽ bị từ chối với mộtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
80import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Việc hủy bỏ một yêu cầu đang diễn ra không hủy bỏ các yêu cầu riêng lẻ của hệ điều hành mà thay vào đó, bộ đệm nội bộ
81 thực hiệnimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Bất kỳ quy định nào phải hỗ trợ đọc
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
82
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Đọc nội dung của liên kết tượng trưng được gọi bởi
47. Xem tài liệu POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
84 để biết thêm chi tiết. Lời hứa được giải quyết vớiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
85 khi thành côngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đối số tùy chọn
78 có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn liên kết được trả về. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn liên kết được trả về sẽ được chuyển dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
90
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Xác định vị trí thực tế của
47 bằng cách sử dụng ngữ nghĩa tương tự như hàmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
92import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Chỉ hỗ trợ các đường dẫn có thể chuyển đổi thành chuỗi UTF8
Đối số tùy chọn
78 có thể là một chuỗi chỉ định mã hóa hoặc một đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn được trả về sẽ được truyền dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Trên Linux, khi nút. js được liên kết với musl libc, hệ thống tệp procfs phải được gắn trên
97 để chức năng này hoạt động. Glibc không có hạn chế nàyimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
98
import { unlink } from 'node:fs';
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
const { unlink } = require['node:fs'];
unlink['/tmp/hello', [err] => {
if [err] throw err;
console.log['successfully deleted /tmp/hello'];
}];
Đổi tên
99 thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
201
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv16. 0. 0
Sử dụng
202 trên một tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
205 trên POSIXv16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Việc sử dụng
202 trên mộtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 không tồn tại sẽ không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204v16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tùy chọn
10 không được dùng nữa, sử dụng tùy chọn này sẽ kích hoạt cảnh báo không dùng nữav14. 14. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tùy chọn
10 không được dùng nữa, thay vào đó hãy sử dụngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
211v13. 3. 0, v12. 16. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tùy chọn
212 được đổi tên thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
213 và giá trị mặc định là 0. Tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
214 đã bị xóa và các lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215 sử dụng logic thử lại giống như các lỗi khác. Tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 hiện được hỗ trợ. Lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217 hiện đã được thử lạiv12. 10. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tùy chọn
10,import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
212 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
214 hiện đã được hỗ trợv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
47. .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
213 Nếu gặp lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
224,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
227 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228, Nút. js thử lại thao tác với thời gian chờ dự phòng tuyến tính dài hơnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 mili giây cho mỗi lần thử. Tùy chọn này đại diện cho số lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Nếuimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, thực hiện xóa thư mục đệ quy. Trong chế độ đệ quy, các hoạt động được thử lại khi thất bại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01. không dùng nữaimport * as fs from 'node:fs';
const fs = require['node:fs'];
216 Lượng thời gian tính bằng mili giây để chờ giữa các lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
239import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xóa thư mục được xác định bởi
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Sử dụng
242 trên tệp [không phải thư mục] dẫn đến lời hứa bị từ chối với lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
205 trên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để có hành vi tương tự như lệnh
245 Unix, hãy sử dụng với các tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
247import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
248
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
47. .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
93 Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97, các ngoại lệ sẽ bị bỏ qua nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 không tồn tại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
213 Nếu gặp lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
224,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
227 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228, Nút. js sẽ thử lại thao tác với thời gian chờ tắt tuyến tính dài hơnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 mili giây cho mỗi lần thử. Tùy chọn này đại diện cho số lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Nếuimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, thực hiện xóa thư mục đệ quy. Trong chế độ đệ quy, các hoạt động được thử lại khi thất bại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
216 Lượng thời gian tính bằng mili giây để chờ giữa các lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
239import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- trả lại. Hoàn thành với
6 khi thành côngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xóa các tệp và thư mục [được mô hình hóa trên tiện ích POSIX
273 tiêu chuẩn]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
274
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv10. 5. 0
Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v10. 0. 0
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
276
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv19. 0. 0
Nếu đối số
277 làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
5 hoặc bị bỏ qua, Nút. js sẽ tự động phát hiện loại 279 và tự động chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
281v10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v10. 0. 0
Tạo một liên kết tượng trưng
Đối số
277 chỉ được sử dụng trên nền tảng Windows và có thể là một trong sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
285. Nếu đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
277 không phải là một chuỗi, Nút. js sẽ tự động phát hiện loạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 và sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 không tồn tại,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284 sẽ được sử dụng. Các điểm giao nhau của Windows yêu cầu đường dẫn đích phải tuyệt đối. Khi sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
285, đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 sẽ tự động được chuẩn hóa thành đường dẫn tuyệt đốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
294
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Cắt bớt [rút ngắn hoặc kéo dài độ dài] của nội dung ở
47 thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
85 byteimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
297
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Nếu
47 đề cập đến một liên kết tượng trưng, thì liên kết đó sẽ bị xóa mà không ảnh hưởng đến tệp hoặc thư mục mà liên kết đó đề cập đến. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 đề cập đến đường dẫn tệp không phải là liên kết tượng trưng, tệp sẽ bị xóa. Xem tài liệu POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
00 để biết thêm chi tiếtimport { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
01
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Thay đổi dấu thời gian hệ thống tệp của đối tượng được tham chiếu bởi
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
03 và import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
04 tuân theo các quy tắc này- Các giá trị có thể là các số đại diện cho thời gian Unix epoch,
05s hoặc một chuỗi số nhưimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
06import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Nếu giá trị không thể được chuyển đổi thành một số hoặc là
07,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09, mộtimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 sẽ bị némimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
11
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v15. 9. 0, v14. 18. 0
12. .import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
78.import * as fs from 'node:fs';
const fs = require['node:fs'];
14 Cho biết liệu quy trình có nên tiếp tục chạy miễn là các tệp đang được xem hay không. Mặc định.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 Cho biết nên xem tất cả các thư mục con hay chỉ thư mục hiện tại. Điều này áp dụng khi một thư mục được chỉ định và chỉ trên các nền tảng được hỗ trợ [Xem ]. Mặc định.import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
87 Chỉ định mã hóa ký tự được sử dụng cho tên tệp được chuyển đến trình nghe. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
24import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
20 Dùng để báo hiệu khi người quan sát nên dừng lạiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại. của các đối tượng với các thuộc tính
Trả về một trình vòng lặp không đồng bộ theo dõi các thay đổi trên
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12, trong đó import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 là một tệp hoặc một thư mục5import * as fs from 'node:fs';
const fs = require['node:fs'];
Trên hầu hết các nền tảng,
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
23 được phát ra bất cứ khi nào tên tệp xuất hiện hoặc biến mất trong thư mụcTất cả các cho
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
24 cũng áp dụng cho import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
25import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
26
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Lịch sửPhiên bảnThay đổiv15. 14. 0, v14. 18. 0
Đối số
08 hỗ trợimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
09,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v15. 2. 0, v14. 17. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số tùy chọn có thể bao gồm AbortSignal để hủy bỏ yêu cầu writeFile đang diễn ra
v14. 0. 0Tham số
08 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Đã thêm vào. v10. 0. 0
Ghi dữ liệu vào tệp không đồng bộ, thay thế tệp nếu tệp đã tồn tại.
08 có thể là một chuỗi, một bộ đệm, một hoặc một đối tượngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tùy chọn
87 bị bỏ qua nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 là bộ đệmimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
48 chỉ ảnh hưởng đến tệp mới tạo. Xem để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Bất kỳ quy định nào phải hỗ trợ viết
Sẽ không an toàn khi sử dụng
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
38 nhiều lần trên cùng một tệp mà không đợi lời hứa được giải quyếtTương tự như
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
39 - import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
40 là một phương thức tiện lợi thực hiện nhiều cuộc gọi import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
41 bên trong để ghi bộ đệm được truyền cho nó. Đối với mã nhạy cảm về hiệu suất, hãy cân nhắc sử dụng hoặcCó thể sử dụng an để hủy một
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
38. Việc hủy bỏ là "nỗ lực tốt nhất" và một số lượng dữ liệu có thể vẫn được ghiViệc hủy bỏ một yêu cầu đang diễn ra không hủy bỏ các yêu cầu riêng lẻ của hệ điều hành mà thay vào đó, bộ đệm nội bộ
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
45 thực hiệnimport { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
46
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v18. 4. 0, v16. 17. 0
Trả về một đối tượng chứa các hằng số thường được sử dụng cho các hoạt động của hệ thống tệp. Đối tượng giống như
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
47. Xem để biết thêm chi tiếtAPI gọi lại
API gọi lại thực hiện tất cả các hoạt động không đồng bộ, không chặn vòng lặp sự kiện, sau đó gọi hàm gọi lại khi hoàn thành hoặc gặp lỗi
API gọi lại sử dụng Nút bên dưới. js để thực hiện các hoạt động của hệ thống tệp ngoài luồng vòng lặp sự kiện. Các hoạt động này không được đồng bộ hóa hoặc luồng an toàn. Phải cẩn thận khi thực hiện nhiều sửa đổi đồng thời trên cùng một tệp, nếu không có thể xảy ra lỗi dữ liệu
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
48
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v6. 3. 0Các hằng số như
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
55, v.v. có mặt trực tiếp trên import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 đã được chuyển vào import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
47 dưới dạng phản đối mềm. Do đó đối với nút. js import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
58 sử dụng import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 để truy cập các hằng số đó hoặc làm điều gì đó như import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
60 để hoạt động với tất cả các phiên bảnv0. 11. 15Đã thêm vào. v0. 11. 15
Kiểm tra quyền của người dùng đối với tệp hoặc thư mục được chỉ định bởi
47. Đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 là một số nguyên tùy chọn chỉ định kiểm tra khả năng truy cập sẽ được thực hiện.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 phải là giá trịimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
50 hoặc mặt nạ bao gồm bitwise OR của bất kỳ giá trị nào trong sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
51,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
52 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
54]. Kiểm tra các giá trị có thể có củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối số cuối cùng,
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49, là một hàm gọi lại được gọi với một đối số lỗi có thể xảy ra. Nếu bất kỳ kiểm tra khả năng truy cập nào không thành công, đối số lỗi sẽ là một đối tượng import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
10. Các ví dụ sau kiểm tra xem 78 có tồn tại không và liệu nó có thể đọc hoặc ghi được khôngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Không sử dụng
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
73 để kiểm tra khả năng truy cập tệp trước khi gọi 64,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 hoặc import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76. Làm như vậy sẽ đưa ra một điều kiện cạnh tranh, vì các quy trình khác có thể thay đổi trạng thái của tệp giữa hai lần gọi. Thay vào đó, mã người dùng nên trực tiếp mở/đọc/ghi tệp và xử lý lỗi phát sinh nếu tệp không thể truy cập đượcviết [KHÔNG ĐƯỢC KHUYẾN NGHỊ]
6import * as fs from 'node:fs';
const fs = require['node:fs'];
viết [KHUYẾN NGHỊ]
7import * as fs from 'node:fs';
const fs = require['node:fs'];
đọc [KHÔNG ĐƯỢC KHUYẾN NGHỊ]
8import * as fs from 'node:fs';
const fs = require['node:fs'];
đọc [KHUYẾN NGHỊ]
9import * as fs from 'node:fs';
const fs = require['node:fs'];
Các ví dụ "không được đề xuất" ở trên kiểm tra khả năng truy cập rồi sử dụng tệp;
Nói chung, chỉ kiểm tra khả năng truy cập của tệp nếu tệp đó sẽ không được sử dụng trực tiếp, ví dụ khi khả năng truy cập tệp là tín hiệu từ một quy trình khác
Trên Windows, các chính sách kiểm soát truy cập [ACL] trên một thư mục có thể giới hạn quyền truy cập vào một tệp hoặc thư mục. Tuy nhiên, hàm
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
73 không kiểm tra ACL và do đó có thể báo cáo rằng một đường dẫn có thể truy cập được ngay cả khi ACL hạn chế người dùng đọc hoặc ghi vào nóimport { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
78
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v7. 0. 0Đối tượng
78 đã qua sẽ không bao giờ được sửa đổiv5. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
281 hiện có thể là một bộ mô tả tệpv0. 6. 7import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 6. 7
Nối dữ liệu vào một tệp không đồng bộ, tạo tệp nếu nó chưa tồn tại.
08 có thể là một chuỗi hoặc mộtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tùy chọn
48 chỉ ảnh hưởng đến tệp mới tạo. Xem để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
1import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 có thể được chỉ định làm bộ mô tả tệp số đã được mở để nối thêm [sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
64 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
93]. Bộ mô tả tệp sẽ không được đóng tự động2import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
94
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 30Đã thêm vào. v0. 1. 30
Thay đổi không đồng bộ các quyền của tệp. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
07 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
3chế độ tập tinimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối số
48 được sử dụng trong cả hai phương phápimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
006 vàimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
007 là một bitmask số được tạo bằng cách sử dụng OR logic của các hằng số sauConstantoctaldescrip mô tảimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Một phương pháp dễ dàng hơn để xây dựng
48 là sử dụng một dãy gồm ba chữ số bát phân [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
027]. Chữ số ngoài cùng bên trái [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
028 trong ví dụ], chỉ định quyền cho chủ sở hữu tệp. Chữ số ở giữa [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
029 trong ví dụ], chỉ định quyền cho nhóm. Chữ số ngoài cùng bên phải [____1030 trong ví dụ], chỉ định quyền cho những người khácSố Mô tảimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
028đọc, viết và thực hiệnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
029đọc và viếtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
030chỉ đọc và thực hiệnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
034chỉ đọcimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
035viết và thực hiệnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
036chỉ viếtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
037chỉ thực hiệnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
39không có quyềnimport * as fs from 'node:fs';
const fs = require['node:fs'];
Ví dụ: giá trị bát phân
039 có nghĩa làimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
- Chủ sở hữu có thể đọc, ghi và thực thi tệp
- Nhóm có thể đọc và ghi tệp
- Những người khác có thể đọc và thực thi tệp
Khi sử dụng các số nguyên trong đó các chế độ tệp được mong đợi, bất kỳ giá trị nào lớn hơn
040 đều có thể dẫn đến các hành vi dành riêng cho nền tảng không được hỗ trợ để hoạt động nhất quán. Do đó, các hằng số nhưimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
041,import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
042 hoặcimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
043 không được hiển thị trongimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
47Hãy cẩn thận. trên Windows chỉ có thể thay đổi quyền ghi và sự khác biệt giữa các quyền của nhóm, chủ sở hữu hoặc những người khác không được triển khai
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
045
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 97Đã thêm vào. v0. 1. 97
Thay đổi không đồng bộ chủ sở hữu và nhóm của tệp. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
72 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
056
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v15. 9. 0, v14. 17. 0Một cuộc gọi lại mặc định hiện được sử dụng nếu không được cung cấp
v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 0. 2Đã thêm vào. v0. 0. 2
Đóng bộ mô tả tập tin. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Gọi
063 trên bất kỳ bộ mô tả tệp nào [import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
064] hiện đang được sử dụng thông qua bất kỳ hoạt độngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 nào khác có thể dẫn đến hành vi không xác địnhXem tài liệu POSIX
066 để biết thêm chi tiếtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
067
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v14. 0. 0Đã thay đổi đối số
10 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 và áp đặt xác thực loại nghiêm ngặt hơnv8. 5. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v8. 5. 0
Sao chép không đồng bộ
72 sangimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. Theo mặc định,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73 được ghi đè nếu nó đã tồn tại. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho hàm gọi lại. Nút. js không đảm bảo về tính nguyên tử của thao tác sao chép. Nếu xảy ra lỗi sau khi tệp đích đã được mở để ghi, Nút. js sẽ cố gắng xóa đíchimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 là một số nguyên tùy chọn chỉ định hành vi của thao tác sao chép. Có thể tạo một mặt nạ bao gồm OR theo bit của hai hoặc nhiều giá trị [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
75]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
77. Thao tác sao chép sẽ thất bại nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73 đã tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
79. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì cơ chế sao chép dự phòng sẽ được sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
80. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành côngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
082
import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v17. 6. 0, v16. 15. 0Chấp nhận tùy chọn
86 bổ sung để chỉ định có thực hiện phân giải đường dẫn cho liên kết tượng trưng hay khôngv16. 7. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v16. 7. 0
72. đường dẫn nguồn để sao chépimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. đường dẫn đích để sao chép vàoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
90 liên kết tượng trưng dereference. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
92 khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
93 làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 và đích tồn tại, đưa ra lỗi. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
96 Chức năng lọc tập tin/thư mục sao chép. Trả lạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97 để sao chép mục này,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 để bỏ qua nó. Cũng có thể trả về mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
99 phân giải thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
93 ghi đè lên tệp hoặc thư mục hiện có. Thao tác sao chép sẽ bỏ qua lỗi nếu bạn đặt giá trị này thành false và đích tồn tại. Sử dụng tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
92 để thay đổi hành vi này. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 Khi dấu thời gian củaimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97 từimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
72 sẽ được giữ nguyên. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
10 sao chép thư mục theo cách đệ quy Mặc định.import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
86 Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97, độ phân giải đường dẫn cho các liên kết tượng trưng sẽ bị bỏ qua. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Sao chép không đồng bộ toàn bộ cấu trúc thư mục từ
72 đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73, bao gồm các thư mục con và tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Khi sao chép một thư mục sang một thư mục khác, khối cầu không được hỗ trợ và hành vi tương tự như
18import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
019
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv16. 10. 0
Tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 không cần phương thức 11 nếu đã cung cấp mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
064v16. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 không cần phương pháp 024 nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v15. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
064 chấp nhận đối số FileHandlev14. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Thay đổi mặc định
00 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
97v13. 6. 0, v12. 17. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 cho phép ghi đè triển khai import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 đã sử dụngv12. 10. 0Bật tùy chọn
00v11. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Áp đặt các hạn chế mới đối với
79 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
80, đưa ra các lỗi phù hợp hơn trong trường hợp chúng tôi không thể xử lý các giá trị đầu vào một cách hợp lýv7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Đối tượng
78 đã qua sẽ không bao giờ được sửa đổiv2. 3. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đối tượng
78 đã qua có thể là một chuỗi bây giờv0. 1. 31import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 31
Không giống như 16 KiB mặc định
76 cho a , luồng được phương pháp này trả về có mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
76 mặc định là 64 KiBimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 có thể bao gồm các giá trịimport * as fs from 'node:fs';
const fs = require['node:fs'];
79 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
80 để đọc một phạm vi byte từ tệp thay vì toàn bộ tệp. Cảimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
79 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
80 đều bao gồm và bắt đầu đếm từ 0, các giá trị được phép nằm trong phạm vi [0,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
83]. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
064 được chỉ định vàimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
79 bị bỏ qua hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6, thì 051 sẽ đọc tuần tự từ vị trí tệp hiện tại.import * as fs from 'node:fs';
const fs = require['node:fs'];
87 có thể là bất kỳ một trong số đó được chấp nhận bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
064 được chỉ định, thìimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
054 sẽ bỏ qua đối sốimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 và sẽ sử dụng bộ mô tả tệp được chỉ định. Điều này có nghĩa là sẽ không có sự kiệnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
056 nào được phát ra.import * as fs from 'node:fs';
const fs = require['node:fs'];
064 nên chặn;import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Nếu
064 trỏ đến một thiết bị ký tự chỉ hỗ trợ chặn đọc [chẳng hạn như bàn phím hoặc card âm thanh], thì thao tác đọc sẽ không kết thúc cho đến khi có dữ liệu. Điều này có thể ngăn quá trình thoát và luồng đóng tự nhiênimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Theo mặc định, luồng sẽ phát ra sự kiện
05 sau khi nó bị hủy. Đặt tùy chọnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 để thay đổi hành vi nàyimport * as fs from 'node:fs';
const fs = require['node:fs'];
Bằng cách cung cấp tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56, có thể ghi đè các triển khai import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 tương ứng cho 11,import * as fs from 'node:fs';
const fs = require['node:fs'];
066 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
024. Khi cung cấp tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56, bắt buộc phải ghi đè cho 066. Nếu không cung cấpimport * as fs from 'node:fs';
const fs = require['node:fs'];
064, thì cũng cần ghi đè choimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
11. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
97, thì cũng cần ghi đè choimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
024import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu
02 là sai, thì bộ mô tả tệp sẽ không bị đóng, ngay cả khi có lỗi. Ứng dụng có trách nhiệm đóng nó và đảm bảo không có rò rỉ bộ mô tả tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 được đặt thành true [hành vi mặc định], trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
05, bộ mô tả tệp sẽ tự động bị đóngimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 đặt chế độ tệp [quyền và bit dính], nhưng chỉ khi tệp được tạoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một ví dụ để đọc 10 byte cuối cùng của tệp dài 100 byte
4import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
081
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv16. 10. 0
Tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 không cần phương thức 11 nếu đã cung cấp mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
064v16. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 không cần phương pháp 024 nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
01v15. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
064 chấp nhận đối số FileHandlev14. 0. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Thay đổi mặc định
00 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
97v13. 6. 0, v12. 17. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 cho phép ghi đè triển khai import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 đã sử dụngv12. 10. 0Bật tùy chọn
00v7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Đối tượng
78 đã qua sẽ không bao giờ được sửa đổiv5. 5. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
02 hiện được hỗ trợv2. 3. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Đối tượng
78 đã qua có thể là một chuỗi bây giờv0. 1. 31import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 31
78 cũng có thể bao gồm tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
79 để cho phép ghi dữ liệu ở một số vị trí sau phần đầu của tệp, các giá trị được phép nằm trong phạm vi [0,import * as fs from 'node:fs';
const fs = require['node:fs'];
83]. Sửa đổi một tệp thay vì thay thế nó có thể yêu cầu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 được đặt thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
12 thay vì mặc định làimport * as fs from 'node:fs';
const fs = require['node:fs'];
706.import * as fs from 'node:fs';
const fs = require['node:fs'];
87 có thể là bất kỳ một trong số đó được chấp nhận bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
02 được đặt thành true [hành vi mặc định] trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
04 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
17, bộ mô tả tệp sẽ tự động bị đóng. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 là sai, thì bộ mô tả tệp sẽ không bị đóng, ngay cả khi có lỗi. Ứng dụng có trách nhiệm đóng nó và đảm bảo không có rò rỉ bộ mô tả tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Theo mặc định, luồng sẽ phát ra sự kiện
05 sau khi nó bị hủy. Đặt tùy chọnimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
00 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
01 để thay đổi hành vi nàyimport * as fs from 'node:fs';
const fs = require['node:fs'];
Bằng cách cung cấp tùy chọn
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56, có thể ghi đè các triển khai import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 tương ứng cho 11,import * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
41, 719 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
024. Ghi đèimport * as fs from 'node:fs';
const fs = require['node:fs'];
721 mà không cóimport * as fs from 'node:fs';
const fs = require['node:fs'];
45 có thể làm giảm hiệu suất vì một số tối ưu hóa [import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
723] sẽ bị vô hiệu hóa. Khi cung cấp tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56, cần ghi đè ít nhất một trong số import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
41 và 719. Nếu không có tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
064 nào được cung cấp, thì cũng cần ghi đè choimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
11. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
02 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
97, thì cũng cần ghi đè choimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
024import * as fs from 'node:fs';
const fs = require['node:fs'];
Giống như, nếu
064 được chỉ định, sẽ bỏ qua đối sốimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
47 và sẽ sử dụng bộ mô tả tệp được chỉ định. Điều này có nghĩa là sẽ không có sự kiệnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
056 nào được phát ra.import * as fs from 'node:fs';
const fs = require['node:fs'];
064 nên chặn;import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
738
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v1. 0. 0Không dùng nữa kể từ. v1. 0. 0
v0. 0. 2Đã thêm vào. v0. 0. 2
Kiểm tra xem đường dẫn đã cho có tồn tại hay không bằng cách kiểm tra với hệ thống tệp. Sau đó gọi đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 với giá trị true hoặc false5import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tham số cho cuộc gọi lại này không nhất quán với các Nút khác. gọi lại js. Thông thường, tham số đầu tiên cho một Nút. js gọi lại là một tham số
746, tùy chọn theo sau là các tham số khác. Cuộc gọi lạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
747 chỉ có một tham số boolean. Đây là một lý do khiếnimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
73 được đề xuất thay vì 747import * as fs from 'node:fs';
const fs = require['node:fs'];
Không nên sử dụng
747 để kiểm tra sự tồn tại của tệp trước khi gọiimport * as fs from 'node:fs';
const fs = require['node:fs'];
64,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 hoặc import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76. Làm như vậy sẽ đưa ra một điều kiện cạnh tranh, vì các quy trình khác có thể thay đổi trạng thái của tệp giữa hai lần gọi. Thay vào đó, mã người dùng nên mở/đọc/ghi tệp trực tiếp và xử lý lỗi phát sinh nếu tệp không tồn tạiviết [KHÔNG ĐƯỢC KHUYẾN NGHỊ]
6import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
viết [KHUYẾN NGHỊ]
7import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
đọc [KHÔNG ĐƯỢC KHUYẾN NGHỊ]
8import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
đọc [KHUYẾN NGHỊ]
9import * as fs from 'node:fs';
const fs = require['node:fs'];
Các ví dụ "không được đề xuất" ở trên kiểm tra sự tồn tại và sau đó sử dụng tệp;
Nói chung, chỉ kiểm tra sự tồn tại của tệp nếu tệp không được sử dụng trực tiếp, chẳng hạn như khi sự tồn tại của tệp là tín hiệu từ một quy trình khác
import * as fs from 'node:fs';
const fs = require['node:fs'];
754
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 4. 7Đã thêm vào. v0. 4. 7
Đặt quyền trên tệp. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
761 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
762
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 4. 7Đã thêm vào. v0. 4. 7
Đặt chủ sở hữu của tập tin. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
769 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
770
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 96Đã thêm vào. v0. 1. 96
Buộc tất cả các hoạt động I/O được xếp hàng hiện tại được liên kết với tệp về trạng thái hoàn thành I/O được đồng bộ hóa của hệ điều hành. Tham khảo tài liệu POSIX
24 để biết chi tiết. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
778
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 5. 0Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 95Đã thêm vào. v0. 1. 95
Gọi lại cuộc gọi với bộ mô tả tệp for
Xem tài liệu POSIX
786 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
787
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 96Đã thêm vào. v0. 1. 96
Yêu cầu tất cả dữ liệu cho bộ mô tả tệp mở được chuyển sang thiết bị lưu trữ. Việc triển khai cụ thể là hệ điều hành và thiết bị cụ thể. Tham khảo tài liệu POSIX
83 để biết thêm chi tiết. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
795
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 8. 6Đã thêm vào. v0. 8. 6
Cắt bớt bộ mô tả tập tin. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
802 để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu tệp được tham chiếu bởi bộ mô tả tệp lớn hơn
85 byte, thì chỉimport * as fs from 'node:fs';
const fs = require['node:fs'];
85 byte đầu tiên sẽ được giữ lại trong tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Ví dụ: chương trình sau chỉ giữ lại bốn byte đầu tiên của tệp
0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Nếu tệp trước đó ngắn hơn
85 byte, nó sẽ được mở rộng và phần mở rộng chứa đầy byte rỗng [import * as fs from 'node:fs';
const fs = require['node:fs'];
88]import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu
85 âm thì sẽ sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
809
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v4. 1. 0Các chuỗi số,
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
07 và import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
08 hiện được phép xác định thời gianv0. 4. 2Đã thêm vào. v0. 4. 2
Thay đổi dấu thời gian hệ thống tệp của đối tượng được tham chiếu bởi bộ mô tả tệp được cung cấp. Nhìn thấy
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
819
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0Lỗi được trả về có thể là
823 nếu có nhiều hơn một lỗi được trả vềv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 4. 7Không dùng nữa kể từ. v0. 4. 7
Thay đổi quyền trên một liên kết tượng trưng. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Phương pháp này chỉ được thực hiện trên macOS
Xem tài liệu POSIX
827 để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
828
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 6. 0API này không còn được dùng nữa
v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 4. 7Ngừng sử dụng tài liệu chỉ
Đặt chủ sở hữu của liên kết tượng trưng. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
835 để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
836
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v14. 5. 0, v12. 19. 0Đã thêm vào. v14. 5. 0, v12. 19. 0
Thay đổi thời gian truy cập và sửa đổi của một tệp giống như cách thay đổi, với điểm khác biệt là nếu đường dẫn đề cập đến một liên kết tượng trưng, thì liên kết đó không được hủy đăng ký. thay vào đó, dấu thời gian của chính liên kết tượng trưng được thay đổi
Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
841
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Các tham số
24 vàimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25 có thể là các đối tượng WHATWGimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 31Đã thêm vào. v0. 1. 31
Tạo một liên kết mới từ ________ 624 đến ________ 625. Xem tài liệu POSIX
26 để biết thêm chi tiết. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
855
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 5. 0Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 30Đã thêm vào. v0. 1. 30
Truy xuất liên kết tượng trưng được tham chiếu bởi đường dẫn. Cuộc gọi lại nhận được hai đối số
866 trong đóimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
867 là một đối tượng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
868 giống vớiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
869, ngoại trừ nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 là một liên kết tượng trưng, thì chính liên kết đó đã được thống kê, không phải tệp mà nó đề cập đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem tài liệu POSIX
31 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
872
import { unlink } from 'node:fs/promises';
try {
await unlink['/tmp/hello'];
console.log['successfully deleted /tmp/hello'];
} catch [error] {
console.error['there was an error:', error.message];
}
const { unlink } = require['node:fs/promises'];
[async function[path] {
try {
await unlink[path];
console.log[`successfully deleted ${path}`];
} catch [error] {
console.error['there was an error:', error.message];
}
}]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v13. 11. 0, v12. 17. 0Ở chế độ
10, cuộc gọi lại hiện nhận đường dẫn được tạo đầu tiên làm đối sốv10. 12. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đối số thứ hai bây giờ có thể là một đối tượng
78 với các thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
10 vàimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
48v10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 8Đã thêm vào. v0. 1. 8
Tạo thư mục không đồng bộ
Cuộc gọi lại được đưa ra một ngoại lệ có thể xảy ra và, nếu
10 làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, đường dẫn thư mục đầu tiên được tạo,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
888.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 vẫn có thể làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6 khi 10 làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, nếu không có thư mục nào được tạoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối số
78 tùy chọn có thể là một số nguyên chỉ địnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 [các bit quyền và dính] hoặc một đối tượng có thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 và thuộc tínhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 cho biết có nên tạo thư mục mẹ hay không. Gọiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
897 khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 là một thư mục tồn tại chỉ dẫn đến lỗi khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 saiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Trên Windows, sử dụng
897 trên thư mục gốc ngay cả với đệ quy sẽ dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem tài liệu POSIX
001 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
002
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v16. 5. 0, v14. 18. 0Tham số
41 hiện chấp nhận một chuỗi rỗngv10. 0. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v6. 2. 1Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 bây giờ là tùy chọnv5. 10. 0Đã thêm vào. v5. 10. 0
Tạo một thư mục tạm thời duy nhất
Tạo sáu ký tự ngẫu nhiên được thêm vào sau một
41 bắt buộc để tạo một thư mục tạm thời duy nhất. Do sự không nhất quán của nền tảng, hãy tránh sử dụng các ký tựimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
43 trongimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
41. Một số nền tảng, đặc biệt là BSD, có thể trả về nhiều hơn sáu ký tự ngẫu nhiên và thay thế các ký tựimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
43 ở cuối trongimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
41 bằng các ký tự ngẫu nhiênimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đường dẫn thư mục đã tạo được truyền dưới dạng chuỗi tới tham số thứ hai của hàm gọi lại
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phương thức
018 sẽ nối trực tiếp sáu ký tự được chọn ngẫu nhiên vào chuỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
41. Ví dụ: được cung cấp một thư mụcimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
51, nếu mục đích là tạo một thư mục tạm thời trongimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
51, thì ____641 phải kết thúc bằng dấu phân cách đường dẫn dành riêng cho nền tảng [import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
54]import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
024
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v11. 1. 0Đối số
10 hiện là tùy chọn và mặc định làimport * as fs from 'node:fs';
const fs = require['node:fs'];
57v9. 9. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Các cờ ________ 2030 và ________ 2031 hiện được hỗ trợ
v7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v0. 0. 2Đã thêm vào. v0. 0. 2
Mở tệp không đồng bộ. Xem tài liệu POSIX
58 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
48 đặt chế độ tệp [quyền và bit dính], nhưng chỉ khi tệp được tạo. Trên Windows, chỉ có thể thao tác quyền ghi;import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Cuộc gọi lại nhận được hai đối số
038import * as fs from 'node:fs';
const fs = require['node:fs'];
Một số ký tự [
59] được dành riêng trong Windows như được ghi lại bằng cách đặt tên tệp, đường dẫn và không gian tên. Trong NTFS, nếu tên tệp chứa dấu hai chấm, Nút. js sẽ mở một luồng hệ thống tệp, như được mô tả bởi this MSDN pageimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Các chức năng dựa trên
64 cũng thể hiện hành vi này.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76, import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75, v.v.import * as fs from 'node:fs';
const fs = require['node:fs'];
043
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v13. 1. 0, v12. 16. 0Tùy chọn
61 đã được giới thiệuv12. 12. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v12. 12. 0
Mở thư mục không đồng bộ. Xem tài liệu POSIX
62 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tạo một , chứa tất cả các chức năng khác để đọc và dọn dẹp thư mục
Tùy chọn
87 đặt mã hóa choimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 trong khi mở thư mục và các thao tác đọc tiếp theoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
051
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 10. 0Tham số
28 bây giờ có thể là bất kỳimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 nào, hoặc mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v7. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
28 bây giờ có thể là mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
059v6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
30 bây giờ có thể làimport * as fs from 'node:fs';
const fs = require['node:fs'];
39v0. 0. 2import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 0. 2
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
28. . Bộ đệm mà dữ liệu sẽ được ghi vàoimport * as fs from 'node:fs';
const fs = require['node:fs'];
29 Vị trí trongimport * as fs from 'node:fs';
const fs = require['node:fs'];
28 để ghi dữ liệu vàoimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 Số byte cần đọcimport * as fs from 'node:fs';
const fs = require['node:fs'];
31. . Chỉ định nơi bắt đầu đọc từ trong tệp. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
5 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
070, dữ liệu sẽ được đọc từ vị trí tệp hiện tại và vị trí tệp sẽ được cập nhật. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 là số nguyên, vị trí tệp sẽ không thay đổiimport * as fs from 'node:fs';
const fs = require['node:fs'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đọc dữ liệu từ tệp được chỉ định bởi
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Cuộc gọi lại được đưa ra ba đối số,
074import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu tệp không được sửa đổi đồng thời, thì kết thúc tệp đạt được khi số byte được đọc bằng 0
Nếu phương thức này được gọi dưới dạng phiên bản chỉnh sửa của nó, thì nó sẽ trả về một lời hứa cho một
076 với các thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
077 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
28import * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
079
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv13. 11. 0, v12. 17. 0
Đã thêm vào. v13. 11. 0, v12. 17. 0
v13. 11. 0, v12. 17. 0Đối tượng tùy chọn có thể được chuyển vào để tạo bộ đệm, độ lệch, độ dài và vị trí tùy chọn
Tương tự như chức năng, phiên bản này có một đối tượng
78 tùy chọn. Nếu không có đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 nào được chỉ định, nó sẽ mặc định với các giá trị trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
083
import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v18. 2. 0, v16. 17. 0
Tương tự như chức năng, phiên bản này có một đối tượng
78 tùy chọn. Nếu không có đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 nào được chỉ định, nó sẽ mặc định với các giá trị trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
087
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 10. 0Tùy chọn mới
66 đã được thêm vàov10. 0. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v6. 0. 0Tham số
78 đã được thêm vàov0. 1. 8import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 8
Đọc nội dung của một thư mục. Cuộc gọi lại nhận được hai đối số
099 trong đóimport * as fs from 'node:fs';
const fs = require['node:fs'];
100 là một mảng tên của các tệp trong thư mục ngoại trừimport * as fs from 'node:fs';
const fs = require['node:fs'];
101 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
102import * as fs from 'node:fs';
const fs = require['node:fs'];
Xem tài liệu POSIX
103 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho tên tệp được chuyển đến hàm gọi lại. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, tên tệp được trả về sẽ được chuyển dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Nếu
71 được đặt thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, mảngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
100 sẽ chứa các đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
111
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0Lỗi được trả về có thể là
823 nếu có nhiều hơn một lỗi được trả vềv15. 2. 0, v14. 17. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối số tùy chọn có thể bao gồm AbortSignal để hủy bỏ yêu cầu readFile đang diễn ra
v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v5. 1. 0import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 sẽ luôn được gọi với import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
5 là tham số 124 trong trường hợp thành côngv5. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
47 hiện có thể là một bộ mô tả tệpv0. 1. 29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 1. 29
Đọc không đồng bộ toàn bộ nội dung của một tệp
1import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Cuộc gọi lại được thông qua hai đối số
126, trong đóimport * as fs from 'node:fs';
const fs = require['node:fs'];
08 là nội dung của tệpimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Nếu không có mã hóa nào được chỉ định, thì bộ đệm thô được trả về
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
2import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Khi đường dẫn là một thư mục, hành vi của
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 và dành riêng cho nền tảng. Trên macOS, Linux và Windows, một lỗi sẽ được trả về. Trên FreeBSD, nội dung của thư mục sẽ được trả vềCó thể hủy bỏ một yêu cầu đang diễn ra bằng cách sử dụng
131. Nếu một yêu cầu bị hủy bỏ, cuộc gọi lại được gọi với mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
80import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Hàm
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 đệm toàn bộ tệp. Để giảm thiểu chi phí bộ nhớ, khi có thể, hãy ưu tiên phát trực tuyến qua 051import * as fs from 'node:fs';
const fs = require['node:fs'];
Việc hủy bỏ một yêu cầu đang diễn ra không hủy bỏ các yêu cầu riêng lẻ của hệ điều hành mà thay vào đó, bộ đệm nội bộ
81 thực hiệnbộ mô tả tệpimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
- Bất kỳ bộ mô tả tệp được chỉ định nào cũng phải hỗ trợ đọc
- Nếu một bộ mô tả tệp được chỉ định là
47, nó sẽ không tự động bị đóngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
- Việc đọc sẽ bắt đầu ở vị trí hiện tại. Ví dụ: nếu tệp đã có _____2137' và sáu byte được đọc với bộ mô tả tệp, lệnh gọi tới _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ với _ _ _ _ _ _ _ _ _ _ _ với _ _ _ _ _ _ _ _ _ với _ _ _ _ _ _ _ _ _ _ với _ _ _ _ _ _ _ _ _ _ _ _ _ với _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Phương thức
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 đọc không đồng bộ nội dung của tệp vào bộ nhớ từng đoạn một, cho phép vòng lặp sự kiện chuyển giữa từng đoạn. Điều này cho phép thao tác đọc ít ảnh hưởng đến hoạt động khác có thể đang sử dụng nhóm luồng libuv cơ bản nhưng có nghĩa là sẽ mất nhiều thời gian hơn để đọc một tệp hoàn chỉnh vào bộ nhớChi phí đọc bổ sung có thể rất khác nhau trên các hệ thống khác nhau và tùy thuộc vào loại tệp đang được đọc. Nếu loại tệp không phải là tệp thông thường [ví dụ: đường ống] và Nút. js không thể xác định kích thước tệp thực tế, mỗi thao tác đọc sẽ tải trên 64 KiB dữ liệu. Đối với các tệp thông thường, mỗi lần đọc sẽ xử lý 512 KiB dữ liệu
Đối với các ứng dụng yêu cầu đọc nội dung tệp nhanh nhất có thể, tốt hơn là sử dụng trực tiếp
080 và mã ứng dụng để quản lý việc đọc toàn bộ nội dung của tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
nút. js GitHub issue #25741 cung cấp thêm thông tin và phân tích chi tiết về hiệu suất của
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 cho nhiều kích thước tệp trong các Nút khác nhau. phiên bản jsimport * as fs from 'node:fs';
const fs = require['node:fs'];
144
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 1. 31Đã thêm vào. v0. 1. 31
Đọc nội dung của liên kết tượng trưng được gọi bởi
47. Cuộc gọi lại nhận được hai đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
155import * as fs from 'node:fs';
const fs = require['node:fs'];
Xem tài liệu POSIX
84 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đối số tùy chọn
78 có thể là một chuỗi chỉ định mã hóa hoặc một đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn liên kết được chuyển đến hàm gọi lại. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn liên kết được trả về sẽ được chuyển dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
161
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v13. 13. 0, v12. 17. 0Đã thêm vào. v13. 13. 0, v12. 17. 0
Đọc từ một tệp được chỉ định bởi
064 và ghi vào một mảng gồm cácimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
166 bằng cách sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
167import * as fs from 'node:fs';
const fs = require['node:fs'];
31 là phần bù từ đầu tệp từ nơi dữ liệu sẽ được đọc. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
169, dữ liệu sẽ được đọc từ vị trí hiện tạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Cuộc gọi lại sẽ được đưa ra ba đối số.
746,import * as fs from 'node:fs';
const fs = require['node:fs'];
077 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
74.import * as fs from 'node:fs';
const fs = require['node:fs'];
077 là số byte đã được đọc từ tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu phương thức này được gọi dưới dạng phiên bản chỉnh sửa của nó, thì nó sẽ trả về một lời hứa cho một
076 với các thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
077 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
74import * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
178
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv8. 0. 0Hỗ trợ giải quyết đường ống/ổ cắm đã được thêm vào
v7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v6. 4. 0Gọi
188 hiện đã hoạt động trở lại đối với các trường hợp cạnh khác nhau trên Windowsv6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
189 đã bị xóav0. 1. 31import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 31
Tính toán không đồng bộ tên đường dẫn chính tắc bằng cách giải quyết các liên kết
190,import * as fs from 'node:fs';
const fs = require['node:fs'];
191 và tượng trưngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Một tên đường dẫn chính tắc không nhất thiết phải là duy nhất. Liên kết cứng và gắn kết liên kết có thể hiển thị một thực thể hệ thống tệp thông qua nhiều tên đường dẫn
Chức năng này hoạt động giống như
192, với một số ngoại lệimport * as fs from 'node:fs';
const fs = require['node:fs'];
Không có chuyển đổi chữ hoa chữ thường được thực hiện trên các hệ thống tệp không phân biệt chữ hoa chữ thường
Số lượng liên kết tượng trưng tối đa không phụ thuộc vào nền tảng và thường cao hơn [nhiều] so với những gì mà triển khai
192 gốc hỗ trợimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 có hai đối số 195. Có thể sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
196 để giải quyết các đường dẫn tương đốiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Chỉ hỗ trợ các đường dẫn có thể chuyển đổi thành chuỗi UTF8
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc một đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn được chuyển đến lệnh gọi lại. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn được trả về sẽ được truyền dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Nếu
47 phân giải thành ổ cắm hoặc đường ống, hàm sẽ trả về tên phụ thuộc hệ thống cho đối tượng đóimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
202
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v9. 2. 0Đã thêm vào. v9. 2. 0
Không đồng bộ
192import * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 có hai đối số 195import * as fs from 'node:fs';
const fs = require['node:fs'];
Chỉ hỗ trợ các đường dẫn có thể chuyển đổi thành chuỗi UTF8
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc một đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn được chuyển đến lệnh gọi lại. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn được trả về sẽ được truyền dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Trên Linux, khi nút. js được liên kết với musl libc, hệ thống tệp procfs phải được gắn trên
97 để chức năng này hoạt động. Glibc không có hạn chế nàyimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
214
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Các tham số
99 vàimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25 có thể là các đối tượng WHATWGimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 0. 2Đã thêm vào. v0. 0. 2
Đổi tên tệp không đồng bộ tại
99 thành tên đường dẫn được cung cấp dưới dạngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25. Trong trường hợpimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25 đã tồn tại, nó sẽ bị ghi đè. Nếu có một thư mục tạiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25, thay vào đó sẽ xảy ra lỗi. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Xem thêm.
229import * as fs from 'node:fs';
const fs = require['node:fs'];
3import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
230
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0Sử dụng
234 trên một tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
205 trên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Việc sử dụng
234 trên mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 không tồn tại sẽ không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204v16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tùy chọn
10 không được dùng nữa, sử dụng tùy chọn này sẽ kích hoạt cảnh báo không dùng nữav14. 14. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tùy chọn
10 không được dùng nữa, thay vào đó hãy sử dụngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
243v13. 3. 0, v12. 16. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
212 được đổi tên thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
213 và giá trị mặc định là 0. Tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
214 đã bị xóa và các lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215 sử dụng logic thử lại giống như các lỗi khác. Tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 hiện được hỗ trợ. Lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217 hiện đã được thử lạiv12. 10. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tùy chọn
10,import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
212 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
214 hiện đã được hỗ trợv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Các tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 0. 2Đã thêm vào. v0. 0. 2
47. .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
213 Nếu gặp lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
224,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
227 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228, Nút. js thử lại thao tác với thời gian chờ dự phòng tuyến tính dài hơnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 mili giây cho mỗi lần thử. Tùy chọn này đại diện cho số lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Nếuimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, thực hiện xóa thư mục đệ quy. Trong chế độ đệ quy, các hoạt động được thử lại khi thất bại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01. không dùng nữaimport * as fs from 'node:fs';
const fs = require['node:fs'];
216 Lượng thời gian tính bằng mili giây để chờ giữa các lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
239import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Không đồng bộ
279. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sử dụng
280 trên tệp [không phải thư mục] dẫn đến lỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
204 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
205 trên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để có hành vi tương tự như lệnh
245 Unix, hãy sử dụng với các tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
247import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
286
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv17. 3. 0, v16. 14. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v14. 14. 0Đã thêm vào. v14. 14. 0
47. .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
93 Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97, các ngoại lệ sẽ bị bỏ qua nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 không tồn tại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
213 Nếu gặp lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
224,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
227 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228, Nút. js sẽ thử lại thao tác với thời gian chờ tắt tuyến tính dài hơnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 mili giây cho mỗi lần thử. Tùy chọn này đại diện cho số lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Nếuimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, thực hiện loại bỏ đệ quy. Trong chế độ đệ quy, các hoạt động được thử lại khi thất bại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
216 Lượng thời gian tính bằng mili giây để chờ giữa các lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
239import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
49import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xóa không đồng bộ các tệp và thư mục [được mô phỏng theo tiện ích POSIX
273 tiêu chuẩn]. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
315
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 5. 0Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 0. 2Đã thêm vào. v0. 0. 2
Không đồng bộ
326. Cuộc gọi lại nhận được hai đối sốimport * as fs from 'node:fs';
const fs = require['node:fs'];
866 trong đóimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
867 là một đối tượngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trong trường hợp có lỗi,
329 sẽ là một trongimport * as fs from 'node:fs';
const fs = require['node:fs'];
Không nên sử dụng
330 để kiểm tra sự tồn tại của tệp trước khi gọiimport * as fs from 'node:fs';
const fs = require['node:fs'];
64,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
75 hoặc import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76. Thay vào đó, mã người dùng nên trực tiếp mở/đọc/ghi tệp và xử lý lỗi phát sinh nếu tệp không khả dụngĐể kiểm tra xem một tệp có tồn tại mà không cần thao tác với nó sau đó hay không, nên
Ví dụ, đưa ra cấu trúc thư mục sau
4import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Chương trình tiếp theo sẽ kiểm tra số liệu thống kê của các đường dẫn đã cho
5import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đầu ra kết quả sẽ giống như
6import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
335
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v12. 0. 0Nếu đối số
277 không được xác định, Node sẽ tự động phát hiện loạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 và tự động chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
281v7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tham số
279 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 có thể là các đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv0. 1. 31Đã thêm vào. v0. 1. 31
Tạo liên kết có tên ________ 347 trỏ đến ______ 3279. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
Xem tài liệu POSIX
349 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số
277 chỉ khả dụng trên Windows và bị bỏ qua trên các nền tảng khác. Nó có thể được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
285. Nếu đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
277 không phải là một chuỗi, Nút. js sẽ tự động phát hiện loạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 và sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 không tồn tại,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284 sẽ được sử dụng. Các điểm giao nhau của Windows yêu cầu đường dẫn đích phải tuyệt đối. Khi sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
285, đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 sẽ tự động được chuẩn hóa thành đường dẫn tuyệt đốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các mục tiêu tương đối có liên quan đến thư mục mẹ của liên kết
7import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Ví dụ trên tạo một liên kết tượng trưng
362 trỏ đếnimport * as fs from 'node:fs';
const fs = require['node:fs'];
363 trong cùng một thư mụcimport * as fs from 'node:fs';
const fs = require['node:fs'];
8import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
364
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v16. 0. 0Lỗi được trả về có thể là
823 nếu có nhiều hơn một lỗi được trả vềv10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 8. 6Đã thêm vào. v0. 8. 6
Cắt bớt tập tin. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành. Một bộ mô tả tệp cũng có thể được chuyển làm đối số đầu tiên. Trong trường hợp này,
372 được gọi làimport * as fs from 'node:fs';
const fs = require['node:fs'];
Truyền một bộ mô tả tệp không được dùng nữa và có thể dẫn đến lỗi trong tương lai
Xem tài liệu POSIX
373 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
374
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 0. 2Đã thêm vào. v0. 0. 2
Xóa không đồng bộ tệp hoặc liên kết tượng trưng. Không có đối số nào khác ngoài một ngoại lệ có thể được đưa ra cho cuộc gọi lại hoàn thành
384 sẽ không hoạt động trên một thư mục, trống hoặc cách khác. Để xóa một thư mục, hãy sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Xem tài liệu POSIX
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
00 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
387
import * as fs from 'node:fs';
const fs = require['node:fs'];
Ngừng theo dõi các thay đổi trên
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12. Nếu 389 được chỉ định, chỉ người nghe cụ thể đó bị xóa. Nếu không, tất cả người nghe sẽ bị xóa, ngừng xemimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 một cách hiệu quảGọi
391 với tên tệp không được xem là không hoạt động, không phải lỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sử dụng hiệu quả hơn
393 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
391. Nên sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
24 thay cho 393 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
391 khi có thểimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
398
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v10. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv8. 0. 0import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
07, import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
08, và import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
09 không còn là bộ chỉ định thời gian hợp lệv7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v4. 1. 0Các chuỗi số,
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
07 và import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
08 hiện được phép xác định thời gianv0. 4. 2Đã thêm vào. v0. 4. 2
Thay đổi dấu thời gian hệ thống tệp của đối tượng được tham chiếu bởi
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
03 và import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
04 tuân theo các quy tắc này- Các giá trị có thể là các số đại diện cho thời gian Unix Epoch tính bằng giây,
05 giây hoặc một chuỗi số nhưimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
06import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- Nếu giá trị không thể được chuyển đổi thành một số hoặc là
07,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09, mộtimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 sẽ bị némimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
422
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv19. 1. 0
Đã thêm hỗ trợ đệ quy cho Linux, AIX và IBMi
v15. 9. 0, v14. 17. 0Đã thêm hỗ trợ để đóng trình theo dõi bằng AbortSignal
v7. 6. 0Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 có thể là một đối tượng WHATWG import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v7. 0. 0Đối tượng
78 đã qua sẽ không bao giờ được sửa đổiv0. 5. 10import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 5. 10
12. .import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
78.import * as fs from 'node:fs';
const fs = require['node:fs'];
14 Cho biết liệu quy trình có nên tiếp tục chạy miễn là các tệp đang được xem hay không. Mặc định.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 Cho biết nên xem tất cả các thư mục con hay chỉ thư mục hiện tại. Điều này áp dụng khi một thư mục được chỉ định và chỉ trên các nền tảng được hỗ trợ [Xem ]. Mặc định.import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
87 Chỉ định mã hóa ký tự được sử dụng cho tên tệp được chuyển đến trình nghe. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
24import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
20 cho phép đóng trình theo dõi bằng AbortSignalimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
389. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
- trả lại.
Theo dõi các thay đổi trên
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12, trong đó import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 là tệp hoặc thư mụcĐối số thứ hai là tùy chọn. Nếu
78 được cung cấp dưới dạng chuỗi, nó chỉ địnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87. Mặt khác,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78 phải được chuyển thành một đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Cuộc gọi lại của người nghe nhận được hai đối số
443.import * as fs from 'node:fs';
const fs = require['node:fs'];
444 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
23 hoặc 446 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 là tên của tệp đã kích hoạt sự kiệnTrên hầu hết các nền tảng,
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
23 được phát ra bất cứ khi nào tên tệp xuất hiện hoặc biến mất trong thư mụcCuộc gọi lại của người nghe được đính kèm với sự kiện
446 được kích hoạt bởi , nhưng nó không giống với giá trịimport * as fs from 'node:fs';
const fs = require['node:fs'];
446 củaimport * as fs from 'node:fs';
const fs = require['node:fs'];
444import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu một
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
20 được thông qua, việc hủy bỏ AbortController tương ứng sẽ đóng kết quả trả vềHãy cẩn thậnAPI
453 không nhất quán 100% trên các nền tảng và không khả dụng trong một số trường hợpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Trên Windows, sẽ không có sự kiện nào được phát ra nếu thư mục đã xem bị di chuyển hoặc đổi tên. Lỗi
228 được báo cáo khi thư mục đã xem bị xóakhả dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tính năng này phụ thuộc vào hệ điều hành cơ bản cung cấp cách thức được thông báo về các thay đổi của hệ thống tệp
- Trên các hệ thống Linux, điều này sử dụng
455import * as fs from 'node:fs';
const fs = require['node:fs'];
- Trên các hệ thống BSD, điều này sử dụng
456import * as fs from 'node:fs';
const fs = require['node:fs'];
- Trên macOS, điều này sử dụng
456 cho tệp vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
458 cho thư mụcimport * as fs from 'node:fs';
const fs = require['node:fs'];
- Trên các hệ thống SunOS [bao gồm cả Solaris và SmartOS], điều này sử dụng
459import * as fs from 'node:fs';
const fs = require['node:fs'];
- Trên hệ thống Windows, tính năng này phụ thuộc vào
460import * as fs from 'node:fs';
const fs = require['node:fs'];
- Trên các hệ thống AIX, tính năng này phụ thuộc vào
461, tính năng này phải được bậtimport * as fs from 'node:fs';
const fs = require['node:fs'];
- Trên các hệ thống IBM i, tính năng này không được hỗ trợ
Nếu chức năng cơ bản không khả dụng vì lý do nào đó, thì
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
24 sẽ không thể hoạt động và có thể đưa ra một ngoại lệ. Ví dụ: việc xem tệp hoặc thư mục có thể không đáng tin cậy và trong một số trường hợp là không thể, trên hệ thống tệp mạng [NFS, SMB, v.v.] hoặc hệ thống tệp máy chủ khi sử dụng phần mềm ảo hóa như Vagrant hoặc DockerVẫn có thể sử dụng
393, sử dụng bỏ phiếu thống kê, nhưng phương pháp này chậm hơn và kém tin cậy hơnnútimport * as fs from 'node:fs';
const fs = require['node:fs'];
Trên các hệ thống Linux và macOS,
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
24 giải quyết đường dẫn đến một nút và xem nút đó. Nếu đường dẫn đã xem bị xóa và tạo lại, nó sẽ được gán một nút mới. Đồng hồ sẽ phát ra một sự kiện để xóa nhưng sẽ tiếp tục xem inode ban đầu. Các sự kiện cho inode mới sẽ không được phát ra. Đây là hành vi dự kiếnCác tệp AIX giữ lại cùng một inode trong suốt thời gian tồn tại của tệp. Lưu và đóng tệp đã xem trên AIX sẽ dẫn đến hai thông báo [một để thêm nội dung mới và một để cắt bớt]
đối số tên tệpViệc cung cấp đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 trong lệnh gọi lại chỉ được hỗ trợ trên Linux, macOS, Windows và AIX. Ngay cả trên các nền tảng được hỗ trợ, import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 không phải lúc nào cũng được đảm bảo cung cấp. Do đó, đừng cho rằng đối số import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 luôn được cung cấp trong hàm gọi lại và có một số logic dự phòng nếu nó là import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
59import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import * as fs from 'node:fs';
const fs = require['node:fs'];
469
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv10. 5. 0
Tùy chọn
470 hiện được hỗ trợv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12 có thể là một đối tượng WHATWG import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 31Đã thêm vào. v0. 1. 31
Theo dõi những thay đổi trên
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
12. Cuộc gọi lại 389 sẽ được gọi mỗi khi tệp được truy cậpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số
78 có thể được bỏ qua. Nếu được cung cấp, nó phải là một đối tượng. Đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 có thể chứa một giá trị logic có tên làimport * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
14 cho biết liệu quy trình có tiếp tục chạy hay không khi các tệp đang được xem. Đối tượng 78 có thể chỉ định thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
480 cho biết tần suất mục tiêu sẽ được thăm dò tính bằng mili giâyimport * as fs from 'node:fs';
const fs = require['node:fs'];
389 nhận hai đối số đối tượng thống kê hiện tại và đối tượng thống kê trước đóimport * as fs from 'node:fs';
const fs = require['node:fs'];
20import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các đối tượng thống kê này là các thể hiện của
482. Nếu tùy chọnimport * as fs from 'node:fs';
const fs = require['node:fs'];
470 làimport * as fs from 'node:fs';
const fs = require['node:fs'];
97, thì các giá trị số trong các đối tượng này được chỉ định làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
485import * as fs from 'node:fs';
const fs = require['node:fs'];
Để được thông báo khi tệp được sửa đổi, không chỉ truy cập, cần so sánh
486 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
487import * as fs from 'node:fs';
const fs = require['node:fs'];
Khi một hoạt động của
488 dẫn đến lỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
204, nó sẽ gọi trình nghe một lần, với tất cả các trường bằng 0 [hoặc, đối với ngày, Unix Epoch]. Nếu tệp được tạo sau này, trình nghe sẽ được gọi lại, với các đối tượng thống kê mới nhất. Đây là một thay đổi về chức năng kể từ v0. 10import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Sử dụng hiệu quả hơn
488 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
492. Nên sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
453 thay choimport * as fs from 'node:fs';
const fs = require['node:fs'];
488 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
492 khi có thểimport * as fs from 'node:fs';
const fs = require['node:fs'];
Khi tệp đang được xem bởi
393 biến mất và xuất hiện lại, thì nội dung củaimport * as fs from 'node:fs';
const fs = require['node:fs'];
497 trong sự kiện gọi lại thứ hai [tệp xuất hiện trở lại] sẽ giống với nội dung củaimport * as fs from 'node:fs';
const fs = require['node:fs'];
497 trong sự kiện gọi lại đầu tiên [sự biến mất của tệp]import * as fs from 'node:fs';
const fs = require['node:fs'];
Điều này xảy ra khi
- tệp bị xóa, sau đó là khôi phục
- tệp được đổi tên và sau đó đổi tên lần thứ hai trở lại tên ban đầu
import * as fs from 'node:fs';
const fs = require['node:fs'];
499
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v14. 0. 0Tham số
28 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 10. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
28 bây giờ có thể là bất kỳimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
057 nàov10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 4. 0Tham số
28 bây giờ có thể là mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
059v7. 2. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Các tham số
29 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 hiện là tùy chọnv7. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 0. 2Đã thêm vào. v0. 0. 2
Viết
28 vào tệp được chỉ định bởiimport * as fs from 'node:fs';
const fs = require['node:fs'];
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
29 xác định phần bộ đệm sẽ được ghi vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 là số nguyên chỉ định số byte cần ghiimport * as fs from 'node:fs';
const fs = require['node:fs'];
31 đề cập đến phần bù từ đầu tệp nơi dữ liệu này sẽ được ghi. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
169, dữ liệu sẽ được ghi ở vị trí hiện tại. Xemimport * as fs from 'node:fs';
const fs = require['node:fs'];
04import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Cuộc gọi lại sẽ được cung cấp ba đối số
521 trong đóimport * as fs from 'node:fs';
const fs = require['node:fs'];
27 chỉ định có bao nhiêu byte được ghi từimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu phương thức này được gọi dưới dạng phiên bản chỉnh sửa của nó, thì nó sẽ trả về một lời hứa cho một
076 với các thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
27 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28import * as fs from 'node:fs';
const fs = require['node:fs'];
Sẽ không an toàn khi sử dụng
528 nhiều lần trên cùng một tệp mà không đợi gọi lại. Đối với kịch bản này, được khuyến nghịimport * as fs from 'node:fs';
const fs = require['node:fs'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
import * as fs from 'node:fs';
const fs = require['node:fs'];
530
import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v18. 3. 0, v16. 17. 0
Viết
28 vào tệp được chỉ định bởiimport * as fs from 'node:fs';
const fs = require['node:fs'];
064import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tương tự như hàm
533 ở trên, phiên bản này có một đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 tùy chọn. Nếu không có đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 nào được chỉ định, nó sẽ mặc định với các giá trị trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
536
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv19. 0. 0
Chuyển đến tham số
15 một đối tượng có chức năngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 riêng không còn được hỗ trợv17. 8. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Chuyển đến tham số
15 một đối tượng có hàm riêngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 không được dùng nữav14. 12. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
15 sẽ xâu chuỗi một đối tượng bằng hàmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 rõ ràngv14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
15 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 2. 0Tham số
31 bây giờ là tùy chọnv7. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v0. 11. 5Đã thêm vào. v0. 11. 5
Viết
15 vào tệp được chỉ định bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
064. Nếuimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
15 không phải là một chuỗi, một ngoại lệ sẽ được đưa raimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 đề cập đến phần bù từ đầu tệp nơi dữ liệu này sẽ được ghi. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
169 dữ liệu sẽ được ghi ở vị trí hiện tại. Xemimport * as fs from 'node:fs';
const fs = require['node:fs'];
04import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 là mã hóa chuỗi dự kiếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Cuộc gọi lại sẽ nhận các đối số
555 trong đóimport * as fs from 'node:fs';
const fs = require['node:fs'];
556 chỉ định số lượng byte mà chuỗi đã truyền cần được ghi. Các byte được viết không nhất thiết giống như các ký tự chuỗi được viết. Nhìn thấyimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sẽ không an toàn khi sử dụng
528 nhiều lần trên cùng một tệp mà không đợi gọi lại. Đối với kịch bản này, được khuyến nghịimport * as fs from 'node:fs';
const fs = require['node:fs'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
Trên Windows, nếu bộ mô tả tệp được kết nối với bảng điều khiển [e. g.
560 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
561], một chuỗi chứa các ký tự không phải ASCII sẽ không được hiển thị chính xác theo mặc định, bất kể mã hóa được sử dụng. Có thể định cấu hình bảng điều khiển để hiển thị đúng UTF-8 bằng cách thay đổi trang mã đang hoạt động bằng lệnhimport * as fs from 'node:fs';
const fs = require['node:fs'];
562. Xem tài liệu chcp để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
563
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv19. 0. 0
Chuyển đến tham số
15 một đối tượng có chức năngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 riêng không còn được hỗ trợv18. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v17. 8. 0Chuyển đến tham số
15 một đối tượng có hàm riêngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
538 không được dùng nữav16. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Lỗi được trả về có thể là
823 nếu có nhiều hơn một lỗi được trả vềv15. 2. 0, v14. 17. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối số tùy chọn có thể bao gồm AbortSignal để hủy bỏ yêu cầu writeFile đang diễn ra
v14. 12. 0Tham số
08 sẽ xâu chuỗi một đối tượng bằng hàmimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 rõ ràngv14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
08 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tham số
08 bây giờ có thể là bất kỳimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
056 hoặc mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v10. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ ném một import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
83 khi chạyv7. 4. 0Tham số
08 bây giờ có thể là mộtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
059v7. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 không còn là tùy chọn. Không vượt qua nó sẽ phát ra cảnh báo không dùng nữa với id DEP0013v5. 0. 0Tham số
281 hiện có thể là một bộ mô tả tệpv0. 1. 29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 1. 29
Khi
281 là tên tệp, ghi dữ liệu không đồng bộ vào tệp, thay thế tệp nếu tệp đã tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 có thể là một chuỗi hoặc một bộ đệmimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Khi
281 là một bộ mô tả tệp, hành vi này tương tự như gọi trực tiếpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 [được khuyến nghị]. Xem ghi chú bên dưới về cách sử dụng bộ mô tả tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
87 bị bỏ qua nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
08 là bộ đệmimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tùy chọn
48 chỉ ảnh hưởng đến tệp mới tạo. Xem để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
21import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
22import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Sẽ không an toàn khi sử dụng
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76 nhiều lần trên cùng một tệp mà không đợi gọi lại. Đối với kịch bản này, được khuyến nghịTương tự như
81 -import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
45 là một phương thức tiện lợi thực hiện nhiều cuộc gọi import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
41 bên trong để ghi bộ đệm được truyền cho nó. Đối với mã nhạy cảm về hiệu suất, hãy cân nhắc sử dụngCó thể sử dụng an để hủy một
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76. Việc hủy bỏ là "nỗ lực tốt nhất" và một số lượng dữ liệu có thể vẫn được ghiViệc hủy bỏ một yêu cầu đang diễn ra không hủy bỏ các yêu cầu riêng lẻ của hệ điều hành mà thay vào đó, bộ đệm nội bộ
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
45 thực hiệnSử dụng import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76 với bộ mô tả tệpKhi
281 là một bộ mô tả tệp, hành vi này gần giống với việc gọi trực tiếpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
528 nhưimport * as fs from 'node:fs';
const fs = require['node:fs'];
23import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Sự khác biệt so với việc gọi trực tiếp
528 là trong một số điều kiện bất thường,import * as fs from 'node:fs';
const fs = require['node:fs'];
528 có thể chỉ ghi một phần của bộ đệm và cần được thử lại để ghi phần dữ liệu còn lại, trong khi đó,import * as fs from 'node:fs';
const fs = require['node:fs'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76 sẽ thử lại cho đến khi dữ liệu được ghi hoàn toàn [hoặc xảy ra lỗi]Ý nghĩa của điều này là một nguồn nhầm lẫn phổ biến. Trong trường hợp mô tả tệp, tệp không được thay thế. Dữ liệu không nhất thiết phải được ghi vào đầu tệp và dữ liệu gốc của tệp có thể vẫn ở trước và/hoặc sau dữ liệu mới được ghi
Ví dụ: nếu
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
76 được gọi hai lần liên tiếp, trước tiên hãy viết chuỗi 608, sau đó viết chuỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
609, tệp sẽ chứaimport * as fs from 'node:fs';
const fs = require['node:fs'];
610 và có thể chứa một số dữ liệu gốc của tệp [tùy thuộc vào kích thước của tệp gốc . Nếu một tên tệp đã được sử dụng thay vì một bộ mô tả, tệp sẽ được đảm bảo chỉ chứaimport * as fs from 'node:fs';
const fs = require['node:fs'];
609import * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
612
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
49 giờ sẽ ném import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
50 thay vì import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
51v12. 9. 0Đã thêm vào. v12. 9. 0
Viết một mảng gồm các
166 vào tệp được chỉ định bởiimport * as fs from 'node:fs';
const fs = require['node:fs'];
064 bằng cách sử dụngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
45import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
31 là phần bù từ đầu tệp nơi dữ liệu này sẽ được ghi. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
169, dữ liệu sẽ được ghi ở vị trí hiện tạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
Cuộc gọi lại sẽ được đưa ra ba đối số.
746,import * as fs from 'node:fs';
const fs = require['node:fs'];
27 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
74.import * as fs from 'node:fs';
const fs = require['node:fs'];
27 là bao nhiêu byte được viết từimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
74import * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu phương thức này là ed, nó sẽ trả về một lời hứa cho một
076 với các thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
27 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
74import * as fs from 'node:fs';
const fs = require['node:fs'];
Sẽ không an toàn khi sử dụng
630 nhiều lần trên cùng một tệp mà không đợi gọi lại. Đối với kịch bản này, sử dụngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
API đồng bộ
Các API đồng bộ thực hiện tất cả các hoạt động một cách đồng bộ, chặn vòng lặp sự kiện cho đến khi hoạt động hoàn thành hoặc không thành công
import * as fs from 'node:fs';
const fs = require['node:fs'];
632
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v0. 11. 15Đã thêm vào. v0. 11. 15
Kiểm tra đồng bộ quyền của người dùng đối với tệp hoặc thư mục được chỉ định bởi
47. Đối sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 là một số nguyên tùy chọn chỉ định kiểm tra khả năng truy cập sẽ được thực hiện.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48 phải là giá trịimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
50 hoặc mặt nạ bao gồm bitwise OR của bất kỳ giá trị nào trong sốimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
51,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
52 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
54]. Kiểm tra các giá trị có thể có củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
48import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu bất kỳ kiểm tra khả năng truy cập nào không thành công, một
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
10 sẽ bị ném. Nếu không, phương thức sẽ trả về import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
624import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
647
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 0. 0
Đối tượng
78 đã qua sẽ không bao giờ được sửa đổiv5. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
281 hiện có thể là một bộ mô tả tệpv0. 6. 7import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 6. 7
Đồng bộ thêm dữ liệu vào một tệp, tạo tệp nếu nó chưa tồn tại.
08 có thể là một chuỗi hoặc mộtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tùy chọn
48 chỉ ảnh hưởng đến tệp mới tạo. Xem để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu
78 là một chuỗi, thì nó chỉ định mã hóaimport * as fs from 'node:fs';
const fs = require['node:fs'];
25import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 có thể được chỉ định làm bộ mô tả tệp số đã được mở để nối thêm [sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
64 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
93]. Bộ mô tả tệp sẽ không được đóng tự độngimport * as fs from 'node:fs';
const fs = require['node:fs'];
657
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v0. 6. 7Đã thêm vào. v0. 6. 7
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
Xem tài liệu POSIX
07 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
663
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
53 sử dụng giao thức import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 97Đã thêm vào. v0. 1. 97
Đồng bộ thay đổi chủ sở hữu và nhóm của một tập tin. Trả lại
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6. Đây là phiên bản đồng bộ củaXem tài liệu POSIX
72 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
670
import * as fs from 'node:fs';
const fs = require['node:fs'];
Đóng bộ mô tả tập tin. Trả lại
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6Gọi
672 trên bất kỳ bộ mô tả tệp nào [import * as fs from 'node:fs';
const fs = require['node:fs'];
064] hiện đang được sử dụng thông qua bất kỳ hoạt độngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
56 nào khác có thể dẫn đến hành vi không xác địnhXem tài liệu POSIX
066 để biết thêm chi tiếtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
676
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv14. 0. 0
Đã thay đổi đối số
10 thànhimport * as fs from 'node:fs';
const fs = require['node:fs'];
48 và áp đặt xác thực loại nghiêm ngặt hơnv8. 5. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v8. 5. 0
Sao chép đồng bộ
72 sangimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. Theo mặc định,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73 được ghi đè nếu nó đã tồn tại. Trả lạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import { open } from 'node:fs/promises';
const fd = await open['sample.txt'];
fd.createReadStream[{ start: 90, end: 99 }];
6. Nút. js không đảm bảo về tính nguyên tử của thao tác sao chép. Nếu xảy ra lỗi sau khi tệp đích đã được mở để ghi, Nút. js sẽ cố gắng xóa đích48 là một số nguyên tùy chọn chỉ định hành vi của thao tác sao chép. Có thể tạo một mặt nạ bao gồm OR theo bit của hai hoặc nhiều giá trị [e. g.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
75]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
77. Thao tác sao chép sẽ thất bại nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73 đã tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
79. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì cơ chế sao chép dự phòng sẽ được sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
80. Thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành côngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
import * as fs from 'node:fs';
const fs = require['node:fs'];
689
import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv17. 6. 0, v16. 15. 0
Chấp nhận tùy chọn
86 bổ sung để chỉ định có thực hiện phân giải đường dẫn cho liên kết tượng trưng hay khôngv16. 7. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v16. 7. 0
72. đường dẫn nguồn để sao chépimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73. đường dẫn đích để sao chép vàoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
90 liên kết tượng trưng dereference. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
92 khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
93 làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 và đích tồn tại, đưa ra lỗi. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
96 Chức năng lọc tập tin/thư mục sao chép. Trả lạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97 để sao chép mục này,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01 để bỏ qua nó. Mặc định.import * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
93 ghi đè lên tệp hoặc thư mục hiện có. Thao tác sao chép sẽ bỏ qua lỗi nếu bạn đặt giá trị này thành false và đích tồn tại. Sử dụng tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
92 để thay đổi hành vi này. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
06 Khi dấu thời gian củaimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97 từimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
72 sẽ được giữ nguyên. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
10 sao chép thư mục theo cách đệ quy Mặc định.import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
86 Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97, độ phân giải đường dẫn cho các liên kết tượng trưng sẽ bị bỏ qua. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
Sao chép đồng bộ toàn bộ cấu trúc thư mục từ
72 đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
73, bao gồm các thư mục con và tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Khi sao chép một thư mục sang một thư mục khác, khối cầu không được hỗ trợ và hành vi tương tự như
18import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
719import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Trả về
97 nếu đường dẫn tồn tại, ngược lại làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
747 không được dùng nữa, nhưngimport * as fs from 'node:fs';
const fs = require['node:fs'];
727 thì không. Tham sốimport * as fs from 'node:fs';
const fs = require['node:fs'];
49 đếnimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
747 chấp nhận các tham số không nhất quán với các Nút khác. gọi lại js.import * as fs from 'node:fs';
const fs = require['node:fs'];
727 không sử dụng gọi lạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
26import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
731import * as fs from 'node:fs';
const fs = require['node:fs'];
Đặt quyền trên tệp. Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xem tài liệu POSIX
761 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
734import * as fs from 'node:fs';
const fs = require['node:fs'];
Đặt chủ sở hữu của tập tin. Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xem tài liệu POSIX
769 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
737import * as fs from 'node:fs';
const fs = require['node:fs'];
Buộc tất cả các hoạt động I/O được xếp hàng hiện tại được liên kết với tệp về trạng thái hoàn thành I/O được đồng bộ hóa của hệ điều hành. Tham khảo tài liệu POSIX
24 để biết chi tiết. Trả lạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
740import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv10. 5. 0
Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv0. 1. 95import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 95
Truy xuất bộ mô tả tập tin
Xem tài liệu POSIX
786 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
743import * as fs from 'node:fs';
const fs = require['node:fs'];
Yêu cầu tất cả dữ liệu cho bộ mô tả tệp mở được chuyển sang thiết bị lưu trữ. Việc triển khai cụ thể là hệ điều hành và thiết bị cụ thể. Tham khảo tài liệu POSIX
83 để biết thêm chi tiết. Trả lạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
746import * as fs from 'node:fs';
const fs = require['node:fs'];
Cắt bớt bộ mô tả tập tin. Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
749import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv4. 1. 0
Các chuỗi số,
07 vàimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 hiện được phép xác định thời gianv0. 4. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 4. 2
Phiên bản đồng bộ của. Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
754import * as fs from 'node:fs';
const fs = require['node:fs'];
Thay đổi quyền trên một liên kết tượng trưng. Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Phương pháp này chỉ được thực hiện trên macOS
Xem tài liệu POSIX
827 để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
757import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv10. 6. 0
API này không còn được dùng nữa
v0. 4. 7Ngừng sử dụng tài liệu chỉ
Đặt chủ sở hữu cho đường dẫn. Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xem tài liệu POSIX
835 để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
760import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v14. 5. 0, v12. 19. 0
Thay đổi dấu thời gian hệ thống tệp của liên kết tượng trưng được tham chiếu bởi
47. Trả vềimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6 hoặc đưa ra một ngoại lệ khi tham số không chính xác hoặc thao tác không thành công. Đây là phiên bản đồng bộ củaimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
764import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Các tham số
24 vàimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25 có thể là các đối tượng WHATWGimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 31
Tạo một liên kết mới từ ________ 624 đến ________ 625. Xem tài liệu POSIX
26 để biết thêm chi tiết. Trả lạiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
773import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv15. 3. 0, v14. 17. 0
Chấp nhận tùy chọn
774 để chỉ định có nên ném ngoại lệ hay không nếu mục nhập không tồn tạiv10. 5. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 30import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 30
Truy xuất liên kết tượng trưng được gọi bởi
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem tài liệu POSIX
31 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
781import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv13. 11. 0, v12. 17. 0
Ở chế độ
10, đường dẫn được tạo đầu tiên được trả về ngay bây giờv10. 12. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đối số thứ hai bây giờ có thể là một đối tượng
78 với các thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
10 vàimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
48v7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Đồng bộ tạo một thư mục. Trả về
6 hoặc nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
10 làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, đường dẫn thư mục đầu tiên được tạo. Đây là phiên bản đồng bộ củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem tài liệu POSIX
001 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
794import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv16. 5. 0, v14. 18. 0
Tham số
41 hiện chấp nhận một chuỗi rỗngv5. 10. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v5. 10. 0
Trả về đường dẫn thư mục đã tạo
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
799import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv13. 1. 0, v12. 16. 0
Tùy chọn
61 đã được giới thiệuv12. 12. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đã thêm vào. v12. 12. 0
Đồng bộ mở một thư mục. Xem
62import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tạo một , chứa tất cả các chức năng khác để đọc và dọn dẹp thư mục
Tùy chọn
87 đặt mã hóa choimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 trong khi mở thư mục và các thao tác đọc tiếp theoimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
804import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv11. 1. 0
Đối số
10 hiện là tùy chọn và mặc định làimport * as fs from 'node:fs';
const fs = require['node:fs'];
57v9. 9. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Các cờ ________ 2030 và ________ 2031 hiện được hỗ trợ
v7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Trả về một số nguyên đại diện cho bộ mô tả tệp
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
813import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv10. 10. 0
Tùy chọn mới
66 đã được thêm vàov7. 6. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Đọc nội dung của thư mục
Xem tài liệu POSIX
103 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Đối số
78 tùy chọn có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho tên tệp được trả về. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, tên tệp được trả về sẽ được chuyển dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Nếu
71 được đặt thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, kết quả sẽ chứa các đối tượngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
825import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v5. 0. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Tham số
47 hiện có thể là một bộ mô tả tệpv0. 1. 8import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 1. 8
Trả về nội dung của
47import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
Nếu tùy chọn
87 được chỉ định thì hàm này trả về một chuỗi. Nếu không, nó trả về một bộ đệmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tương tự như , khi đường dẫn là một thư mục, hành vi của
130 là dành riêng cho nền tảngimport * as fs from 'node:fs';
const fs = require['node:fs'];
835import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 31
Trả về giá trị chuỗi của liên kết tượng trưng
Xem tài liệu POSIX
84 để biết thêm chi tiếtimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Đối số tùy chọn
78 có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn liên kết được trả về. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn liên kết được trả về sẽ được chuyển dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
844import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv10. 10. 0
Tham số
28 bây giờ có thể là bất kỳimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
057 nàov6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
30 bây giờ có thể làimport * as fs from 'node:fs';
const fs = require['node:fs'];
39v0. 1. 21import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 21
Trả về số của
077import * as fs from 'node:fs';
const fs = require['node:fs'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
852import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv13. 13. 0, v12. 17. 0
Đã thêm vào. v13. 13. 0, v12. 17. 0
v13. 13. 0, v12. 17. 0Đối tượng tùy chọn có thể được chuyển vào để tạo độ lệch, độ dài và vị trí tùy chọn
Trả về số của
077import * as fs from 'node:fs';
const fs = require['node:fs'];
Tương tự như hàm
854 ở trên, phiên bản này có một đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 tùy chọn. Nếu không có đối tượngimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 nào được chỉ định, nó sẽ mặc định với các giá trị trênimport * as fs from 'node:fs';
const fs = require['node:fs'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
858import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v13. 13. 0, v12. 17. 0
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
860import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv8. 0. 0
Hỗ trợ giải quyết đường ống/ổ cắm đã được thêm vào
v7. 6. 0Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v6. 4. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Gọi
864 hiện đã hoạt động trở lại đối với các trường hợp cạnh khác nhau trên Windowsv6. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
189 đã bị xóav0. 1. 31import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 31
Trả về tên đường dẫn đã giải quyết
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
867import * as fs from 'node:fs';
const fs = require['node:fs'];
Đồng bộ
192import * as fs from 'node:fs';
const fs = require['node:fs'];
Chỉ hỗ trợ các đường dẫn có thể chuyển đổi thành chuỗi UTF8
Đối số tùy chọn
78 có thể là một chuỗi chỉ định mã hóa hoặc đối tượng có thuộc tínhimport * as fs from 'node:fs';
const fs = require['node:fs'];
87 chỉ định mã hóa ký tự sẽ sử dụng cho đường dẫn được trả về. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, đường dẫn được trả về sẽ được truyền dưới dạng đối tượngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Trên Linux, khi nút. js được liên kết với musl libc, hệ thống tệp procfs phải được gắn trên
97 để chức năng này hoạt động. Glibc không có hạn chế nàyimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
874import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Các tham số
99 vàimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25 có thể là các đối tượng WHATWGimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Đổi tên tệp từ
99 thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
25. Trả lạiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Xem tài liệu POSIX
229 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
883import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv16. 0. 0
Sử dụng
884 trên một tệpimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
205 trên POSIXv16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Việc sử dụng
884 trên mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 không tồn tại sẽ không còn được phép và dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204v16. 0. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tùy chọn
10 không được dùng nữa, sử dụng tùy chọn này sẽ kích hoạt cảnh báo không dùng nữav14. 14. 0import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
Tùy chọn
10 không được dùng nữa, thay vào đó hãy sử dụngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
893v13. 3. 0, v12. 16. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tùy chọn
212 được đổi tên thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
213 và giá trị mặc định là 0. Tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
214 đã bị xóa và các lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215 sử dụng logic thử lại giống như các lỗi khác. Tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 hiện được hỗ trợ. Lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217 hiện đã được thử lạiv12. 10. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tùy chọn
10,import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
212 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
214 hiện đã được hỗ trợv7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
47. .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
213 Nếu gặp lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
224,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
227 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228, Nút. js thử lại thao tác với thời gian chờ dự phòng tuyến tính dài hơnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 mili giây cho mỗi lần thử. Tùy chọn này đại diện cho số lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Nếuimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, thực hiện xóa thư mục đệ quy. Trong chế độ đệ quy, các hoạt động được thử lại khi thất bại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01. không dùng nữaimport * as fs from 'node:fs';
const fs = require['node:fs'];
216 Lượng thời gian tính bằng mili giây để chờ giữa các lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
239import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đồng bộ
279. Trả lạiimport * as fs from 'node:fs';
const fs = require['node:fs'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Sử dụng
927 trên tệp [không phải thư mục] dẫn đến lỗiimport * as fs from 'node:fs';
const fs = require['node:fs'];
204 trên Windows và lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
205 trên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để có hành vi tương tự như lệnh
245 Unix, hãy sử dụng với các tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
247import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
933import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv17. 3. 0, v16. 14. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v14. 14. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v14. 14. 0
47. .import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
78import * as fs from 'node:fs';
const fs = require['node:fs'];
93 Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
97, các ngoại lệ sẽ bị bỏ qua nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 không tồn tại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
213 Nếu gặp lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
224,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
217,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
227 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228, Nút. js sẽ thử lại thao tác với thời gian chờ tắt tuyến tính dài hơnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
216 mili giây cho mỗi lần thử. Tùy chọn này đại diện cho số lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39import * as fs from 'node:fs';
const fs = require['node:fs'];
10 Nếuimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, thực hiện xóa thư mục đệ quy. Trong chế độ đệ quy, các hoạt động được thử lại khi thất bại. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
01import * as fs from 'node:fs';
const fs = require['node:fs'];
216 Lượng thời gian tính bằng mili giây để chờ giữa các lần thử lại. Tùy chọn này bị bỏ qua nếu tùy chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
10 không phải làimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97. Mặc định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
239import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xóa đồng bộ các tệp và thư mục [được mô hình hóa trên tiện ích POSIX
273 tiêu chuẩn]. Trả lạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
962import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv15. 3. 0, v14. 17. 0
Chấp nhận tùy chọn
774 để chỉ định có nên ném ngoại lệ hay không nếu mục nhập không tồn tạiv10. 5. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Chấp nhận một đối tượng
78 bổ sung để chỉ định xem các giá trị số được trả về có phải là bigint hay khôngv7. 6. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Truy xuất đường dẫn
968import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv12. 0. 0
Nếu đối số
277 không được xác định, Node sẽ tự động phát hiện loạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 và tự động chọnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
281v7. 6. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các tham số
279 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 có thể là các đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54. Hỗ trợ hiện vẫn đang thử nghiệmv0. 1. 31import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 31
Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
979import * as fs from 'node:fs';
const fs = require['node:fs'];
Cắt bớt tập tin. Trả lại
6. Một bộ mô tả tệp cũng có thể được chuyển làm đối số đầu tiên. Trong trường hợp này,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
981 được gọi làimport * as fs from 'node:fs';
const fs = require['node:fs'];
Truyền một bộ mô tả tệp không được dùng nữa và có thể dẫn đến lỗi trong tương lai
982import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv7. 6. 0
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v0. 1. 21import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 1. 21
Đồng bộ
00. Trả lạiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
988import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnChangesv8. 0. 0
07,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08, vàimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
09 không còn là bộ chỉ định thời gian hợp lệv7. 6. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Tham số
47 có thể là một đối tượng WHATWGimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
53 sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54v4. 1. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các chuỗi số,
07 vàimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
08 hiện được phép xác định thời gianv0. 4. 2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v0. 4. 2
Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
999import * as fs from 'node:fs';
const fs = require['node:fs'];
Lịch sửPhiên bảnThay đổiv19. 0. 0
Chuyển đến tham số
08 một đối tượng có chức năngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 riêng không còn được hỗ trợv17. 8. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Chuyển đến tham số
08 một đối tượng có hàm riêngimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 không được dùng nữav14. 12. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
08 sẽ xâu chuỗi một đối tượng bằng hàmimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
538 rõ ràngv14. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
08 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 10. 0import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Tham số
08 bây giờ có thể là bất kỳimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
056 hoặc mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
057v7. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
08 bây giờ có thể là mộtimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
059v5. 0. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
281 hiện có thể là một bộ mô tả tệpv0. 1. 29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v0. 1. 29
Trả lại
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Tùy chọn
48 chỉ ảnh hưởng đến tệp mới tạo. Xem để biết thêm chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
017import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
Tham số
28 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav10. 10. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
28 bây giờ có thể là bất kỳimport * as fs from 'node:fs';
const fs = require['node:fs'];
056 hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
057 nàov7. 4. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Tham số
28 bây giờ có thể là mộtimport * as fs from 'node:fs';
const fs = require['node:fs'];
059v7. 2. 0import * as fs from 'node:fs';
const fs = require['node:fs'];
Các tham số
29 vàimport * as fs from 'node:fs';
const fs = require['node:fs'];
30 hiện là tùy chọnv0. 1. 21import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 1. 21
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
027import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v18. 3. 0, v16. 17. 0
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
029import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv14. 0. 0
Tham số
15 sẽ không ép buộc đầu vào không được hỗ trợ vào chuỗi nữav7. 2. 0import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tham số
31 bây giờ là tùy chọnv0. 11. 5import * as fs from 'node:fs';
const fs = require['node:fs'];
Đã thêm vào. v0. 11. 5
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
033import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Để biết thông tin chi tiết, hãy xem tài liệu về phiên bản không đồng bộ của API này.
Những vật thông thường
Các đối tượng chung được chia sẻ bởi tất cả các biến thể API hệ thống tệp [lời hứa, gọi lại và đồng bộ]
Lớp.
035import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một lớp đại diện cho một luồng thư mục
Được tạo bởi , , hoặc
2import * as fs from 'node:fs';
const fs = require['node:fs'];
Khi sử dụng async iterator, đối tượng sẽ tự động đóng sau khi iterator thoát
039import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đóng xử lý tài nguyên cơ bản của thư mục một cách không đồng bộ. Các lần đọc tiếp theo sẽ dẫn đến lỗi
Một lời hứa được trả lại sẽ được giải quyết sau khi tài nguyên đã bị đóng
040import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnThay đổiv18. 0. 0
Chuyển một cuộc gọi lại không hợp lệ cho đối số
49 giờ sẽ némimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
50 thay vìimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
51v12. 12. 0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đã thêm vào. v12. 12. 0
Đóng xử lý tài nguyên cơ bản của thư mục một cách không đồng bộ. Các lần đọc tiếp theo sẽ dẫn đến lỗi
49 sẽ được gọi sau khi xử lý tài nguyên đã bị đóngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
045import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đóng đồng bộ xử lý tài nguyên cơ bản của thư mục. Các lần đọc tiếp theo sẽ dẫn đến lỗi
046import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đường dẫn chỉ đọc của thư mục này như được cung cấp cho , , hoặc
050import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đọc không đồng bộ mục nhập thư mục tiếp theo qua
103 dưới dạngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Một lời hứa được trả lại sẽ được giải quyết bằng , hoặc
5 nếu không còn mục nhập thư mục nào để đọcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các mục nhập thư mục được hàm này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
053import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đọc không đồng bộ mục nhập thư mục tiếp theo qua
103 dưới dạngimport * as fs from 'node:fs';
const fs = require['node:fs'];
Sau khi đọc xong,
49 sẽ được gọi với dấu , hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
5 nếu không còn mục nhập thư mục nào để đọcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các mục nhập thư mục được hàm này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
057import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đọc đồng bộ mục nhập thư mục tiếp theo dưới dạng. Xem tài liệu POSIX
103 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Nếu không còn mục nào trong thư mục để đọc, thì sẽ trả về
5import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Các mục nhập thư mục được hàm này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
060import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lặp lại không đồng bộ trên thư mục cho đến khi tất cả các mục đã được đọc. Tham khảo tài liệu POSIX
103 để biết thêm chi tiếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
Các mục được trả về bởi trình vòng lặp không đồng bộ luôn là một. Trường hợp
5 từimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
050 được xử lý nội bộimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Xem ví dụ
Các mục nhập thư mục được trình vòng lặp này trả về không theo thứ tự cụ thể như được cung cấp bởi các cơ chế thư mục cơ bản của hệ điều hành. Các mục được thêm hoặc xóa trong khi lặp qua thư mục có thể không được đưa vào kết quả lặp
Lớp.
064import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một đại diện của một mục nhập thư mục, có thể là một tệp hoặc thư mục con trong thư mục, được trả về bằng cách đọc từ một. Mục nhập thư mục là sự kết hợp của các cặp tên tệp và loại tệp
Ngoài ra, khi or được gọi với tùy chọn
66 được đặt thànhimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
97, mảng kết quả được lấp đầy bằng các đối tượng, thay vì các chuỗi hoặc simport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
069import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị khốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
071import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị ký tựimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
073import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả thư mục hệ thống tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
075import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả ống nhập trước xuất trước [FIFO]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
077import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một tệp thông thườngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
079import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một ổ cắmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
081import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một liên kết tượng trưngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
083import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Tên tệp mà đối tượng này đề cập đến. Loại giá trị này được xác định bởi
65 được chuyển đến hoặcimport * as fs from 'node:fs';
const fs = require['node:fs'];
Lớp.
087import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Gọi phương thức thành công sẽ trả về một đối tượng mới
Tất cả các đối tượng phát ra sự kiện
446 bất cứ khi nào một tệp đã xem cụ thể được sửa đổiBiến cố.import * as fs from 'node:fs';
const fs = require['node:fs'];
446import * as fs from 'node:fs';
const fs = require['node:fs'];
444 Loại sự kiện thay đổi đã xảy raimport * as fs from 'node:fs';
const fs = require['node:fs'];
12. Tên tệp đã thay đổi [nếu có/có liên quan]import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Phát ra khi có gì đó thay đổi trong thư mục hoặc tệp đã xem. Xem thêm chi tiết tại
Đối số
12 có thể không được cung cấp tùy thuộc vào sự hỗ trợ của hệ điều hành. Nếu cung cấpimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
12, nó sẽ được cung cấp dưới dạng nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
24 được gọi với tùy chọnimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
87 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
70, nếu không thìimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
12 sẽ là chuỗi UTF-8Biến cố.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Được phát ra khi người xem ngừng theo dõi các thay đổi. Đối tượng đã đóng không còn sử dụng được trong trình xử lý sự kiện
Biến cố.
04import * as fs from 'node:fs';
const fs = require['node:fs'];
Xuất hiện khi xảy ra lỗi trong khi xem tệp. Đối tượng bị lỗi không còn sử dụng được trong trình xử lý sự kiện
102import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ngừng theo dõi các thay đổi trên đã cho. Sau khi dừng, đối tượng không còn sử dụng được nữa
103import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, yêu cầu Node. vòng lặp sự kiện js không thoát miễn là nó đang hoạt động. Gọi
103 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Theo mặc định, tất cả các đối tượng đều được "ref'ed", khiến việc gọi
103 thông thường không cần thiết trừ khi trước đó đã gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
106import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
106import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, đối tượng hoạt động sẽ không yêu cầu Nút. vòng lặp sự kiện js để duy trì hoạt động. Nếu không có hoạt động nào khác giữ cho vòng lặp sự kiện chạy, quy trình có thể thoát trước khi lệnh gọi lại của đối tượng được gọi. Gọi
106 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
109import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Một cuộc gọi thành công đến phương thức
393 sẽ trả về một đối tượng mớiimport * as fs from 'node:fs';
const fs = require['node:fs'];
103import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, yêu cầu Node. vòng lặp sự kiện js không thoát miễn là nó đang hoạt động. Gọi
103 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Theo mặc định, tất cả các đối tượng đều được "ref'ed", khiến việc gọi
103 thông thường không cần thiết trừ khi trước đó đã gọiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
106import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
106import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v14. 3. 0, v12. 20. 0
Khi được gọi, đối tượng hoạt động sẽ không yêu cầu Nút. vòng lặp sự kiện js để duy trì hoạt động. Nếu không có hoạt động nào khác giữ cho vòng lặp sự kiện chạy, quy trình có thể thoát trước khi lệnh gọi lại của đối tượng được gọi. Gọi
106 nhiều lần sẽ không có hiệu lựcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
117import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các trường hợp được tạo và trả về bằng cách sử dụng hàm
Biến cố.
05import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Được phát ra khi bộ mô tả tệp cơ bản của đã bị đóng
Biến cố.
056import * as fs from 'node:fs';
const fs = require['node:fs'];
Được phát ra khi bộ mô tả tệp của đã được mở
Biến cố.
121import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phát ra khi đã sẵn sàng để được sử dụng
Cháy ngay sau
056import * as fs from 'node:fs';
const fs = require['node:fs'];
123import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số lượng byte đã được đọc cho đến nay
124import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đường dẫn đến tệp mà luồng đang đọc từ đó như được chỉ định trong đối số đầu tiên của
051. Nếuimport * as fs from 'node:fs';
const fs = require['node:fs'];
47 được truyền dưới dạng chuỗi, thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
124 sẽ là chuỗi. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 được chuyển thành a , thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
124 sẽ là a. Nếu chỉ địnhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
064 thìimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
124 sẽ làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
6import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
133import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đã thêm vào. v11. 2. 0, v10. 16. 0
Thuộc tính này là
97 nếu tệp cơ bản chưa được mở, tôi. e. trước khi sự kiệnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
121 được phát raimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
136import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lịch sửPhiên bảnChangesv8. 1. 0
Đã thêm lần dưới dạng số
v0. 1. 21Đã thêm vào. v0. 1. 21
Một đối tượng cung cấp thông tin về một tập tin
Các đối tượng được trả về từ , , và các đối tượng đồng bộ của chúng thuộc loại này. Nếu
470 trongimport * as fs from 'node:fs';
const fs = require['node:fs'];
78 được truyền cho các phương thức đó là đúng, thì các giá trị số sẽ làimport * as fs from 'node:fs';
const fs = require['node:fs'];
470 thay vìimport * as fs from 'node:fs';
const fs = require['node:fs'];
77 và đối tượng sẽ chứa các thuộc tính chính xác nano giây bổ sung có hậu tố làimport * as fs from 'node:fs';
const fs = require['node:fs'];
144import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
28import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phiên bản
470import * as fs from 'node:fs';
const fs = require['node:fs'];
29import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
146import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị khốiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
148import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một thiết bị ký tựimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
150import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả thư mục hệ thống tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Nếu đối tượng được lấy từ , phương thức này sẽ luôn trả về
01. Điều này là do trả về thông tin về chính liên kết tượng trưng chứ không phải đường dẫn mà nó giải quyếtimport * as fs from 'node:fs';
const fs = require['node:fs'];
155import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả ống nhập trước xuất trước [FIFO]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
157import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một tệp thông thườngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
159import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một ổ cắmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
161import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trả về
97 nếu đối tượng mô tả một liên kết tượng trưngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phương pháp này chỉ có hiệu lực khi sử dụng
164import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số nhận dạng của thiết bị chứa tệp
165import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số "Inode" cụ thể của hệ thống tệp cho tệp
166import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Một trường bit mô tả loại tệp và chế độ
167import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số lượng liên kết cứng tồn tại cho tệp
168import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Định danh người dùng dạng số của người dùng sở hữu tệp [POSIX]
169import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số nhận dạng nhóm số của nhóm sở hữu tệp [POSIX]
170import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số nhận dạng thiết bị số nếu tệp đại diện cho một thiết bị
171import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Kích thước của tệp tính bằng byte
Nếu hệ thống tệp cơ bản không hỗ trợ nhận kích thước của tệp, điều này sẽ là
39import * as fs from 'node:fs';
const fs = require['node:fs'];
173import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Kích thước khối hệ thống tệp cho các thao tác i/o
174import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số khối được phân bổ cho tệp này
175import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng tệp này được truy cập được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
176import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng tệp này được sửa đổi được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
177import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng trạng thái tệp được thay đổi được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
178import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết thời gian tạo tệp này được biểu thị bằng mili giây kể từ Kỷ nguyên POSIX
179import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết lần cuối cùng tệp này được truy cập được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
181import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết lần cuối cùng tệp này được sửa đổi được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
183import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết lần cuối cùng trạng thái tệp được thay đổi được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
185import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Chỉ xuất hiện khi
180 được chuyển vào phương thức tạo đối tượng. Dấu thời gian cho biết thời gian tạo tệp này được biểu thị bằng nano giây kể từ Kỷ nguyên POSIXimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
187import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối tệp này được truy cập
188import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối cùng tệp này được sửa đổi
189import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết lần cuối trạng thái tệp được thay đổi
190import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Dấu thời gian cho biết thời gian tạo tệp này
Giá trị thời gian thống kêCác thuộc tính
191,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
192,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
193,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
194 là các giá trị số chứa thời gian tương ứng tính bằng mili giây. Độ chính xác của chúng là nền tảng cụ thể. Khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
180 được chuyển vào phương thức tạo đối tượng, các thuộc tính sẽ là bigint, nếu không chúng sẽ làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các thuộc tính
196,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
197,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
198,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
199 là các bigint giữ thời gian tương ứng tính bằng nano giây. Chúng chỉ xuất hiện khiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
180 được truyền vào phương thức tạo đối tượng. Độ chính xác của chúng là nền tảng cụ thểimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
04,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
203 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 là các đại diện thay thế đối tượng củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
05 trong các thời điểm khác nhau. Giá trịimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05 và số không được kết nối. Việc chỉ định một giá trị số mới hoặc thay đổi giá trịimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
05 sẽ không được phản ánh trong biểu diễn thay thế tương ứngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Thời gian trong đối tượng stat có ngữ nghĩa sau
03 "Thời gian truy cập". Thời gian khi dữ liệu tệp được truy cập lần cuối. Được thay đổi bởi các cuộc gọi hệ thốngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
209,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
210 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
211import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
04 "Thời gian sửa đổi". Thời gian khi dữ liệu tệp được sửa đổi lần cuối. Được thay đổi bởi các cuộc gọi hệ thốngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
209,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
210 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
203 "Thay đổi thời gian". Thời gian khi trạng thái tệp được thay đổi lần cuối [sửa đổi dữ liệu inode]. Được thay đổi bởi các cuộc gọi hệ thốngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
07,import * as fs from 'node:fs';
const fs = require['node:fs'];
72,import * as fs from 'node:fs';
const fs = require['node:fs'];
26,import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
209,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
229,import * as fs from 'node:fs';
const fs = require['node:fs'];
00,import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
210,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
211 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
215import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 "Giờ sinh". Thời gian tạo tập tin. Đặt một lần khi tệp được tạo. Trên các hệ thống tệp không có sẵn thời gian sinh, thay vào đó, trường này có thể chứaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
203 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
228 [tức là dấu thời gian kỷ nguyên Uniximport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
39]. Giá trị này có thể lớn hơnimport * as fs from 'node:fs';
const fs = require['node:fs'];
03 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
04 trong trường hợp này. Trên Darwin và các biến thể FreeBSD khác, cũng được đặt nếuimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
03 được đặt rõ ràng thành giá trị sớm hơn giá trị hiện tại củaimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
204 bằng lệnh gọi hệ thốngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
210import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trước nút. js 0. 12,
203 giữimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
204 trên hệ thống Windows. kể từ 0. 12,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
203 không phải là "thời gian sáng tạo" và trên các hệ thống Unix, nó chưa bao giờ làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Lớp.
238import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các trường hợp được tạo và trả về bằng cách sử dụng hàm
Biến cố.
05import * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Được phát ra khi bộ mô tả tệp cơ bản của đã bị đóng
Biến cố.
056import * as fs from 'node:fs';
const fs = require['node:fs'];
Phát ra khi tệp của được mở
Biến cố.
121import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Phát ra khi đã sẵn sàng để được sử dụng
Cháy ngay sau
056import * as fs from 'node:fs';
const fs = require['node:fs'];
244import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Số lượng byte được ghi cho đến nay. Không bao gồm dữ liệu vẫn đang xếp hàng để ghi
245import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đóng
246. Tùy chọn chấp nhận một cuộc gọi lại sẽ được thực hiện sau khi đóngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
246import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
248import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đường dẫn đến tệp mà luồng đang ghi vào như được chỉ định trong đối số đầu tiên của. Nếu
47 được truyền dưới dạng chuỗi, thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
248 sẽ là chuỗi. Nếuimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47 được chuyển thành a , thìimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
248 sẽ là aimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
254import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Thuộc tính này là
97 nếu tệp cơ bản chưa được mở, tôi. e. trước khi sự kiệnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
121 được phát raimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
47import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Trả về một đối tượng chứa các hằng số thường được sử dụng cho các hoạt động của hệ thống tệp
hằng số FSCác hằng số sau đây được xuất bởi
47 vàimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
46import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Không phải mọi hằng số sẽ có sẵn trên mọi hệ điều hành; . Đối với các ứng dụng di động, nên kiểm tra sự hiện diện của chúng trước khi sử dụng
Để sử dụng nhiều hơn một hằng số, hãy sử dụng toán tử bitwise OR
260import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ví dụ
Hằng số truy cập tệpCác hằng số sau đây được dùng làm tham số
48 được truyền cho , vàConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
265Cờ cho biết tệp hiển thị với quy trình gọi. Điều này hữu ích để xác định xem một tệp có tồn tại hay không, nhưng không nói gì về quyền củaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
266. Mặc định nếu không có chế độ nào được chỉ định.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
267Cờ cho biết quá trình gọi có thể đọc tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
268Cờ chỉ ra rằng tệp có thể được ghi bởi quá trình gọi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
269Cờ chỉ ra rằng tệp có thể được thực thi bởi quy trình gọi. Điều này không ảnh hưởng đến Windows [sẽ hoạt động nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
50]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các định nghĩa cũng có sẵn trên Windows
Hằng số sao chép tệpCác hằng số sau đây có nghĩa là để sử dụng với
ConstantDescription
272Nếu có, thao tác sao chép sẽ không thành công với lỗi nếu đường dẫn đích đã tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
273Nếu có, thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng cơ bản không hỗ trợ sao chép khi ghi, thì cơ chế sao chép dự phòng sẽ được sử dụng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
274Nếu có, thao tác sao chép sẽ cố gắng tạo liên kết giới thiệu sao chép khi ghi. Nếu nền tảng cơ bản không hỗ trợ sao chép khi ghi, thì thao tác sẽ không thành công với lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các định nghĩa cũng có sẵn trên Windows
Các hằng số mở tệpCác hằng số sau đây được dùng với
64ConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
276Cờ cho biết mở tệp để truy cập chỉ đọc.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
277Cờ cho biết mở tệp để truy cập chỉ ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
278Cờ cho biết mở tệp để truy cập đọc-ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279Cờ cho biết để tạo tệp nếu nó chưa tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280Cờ cho biết rằng việc mở tệp sẽ không thành công nếu cờimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279 được đặt và tệp đã tồn tại.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
282Cờ chỉ ra rằng nếu đường dẫn xác định một thiết bị đầu cuối, thì việc mở đường dẫn sẽ không khiến thiết bị đầu cuối đó trở thành thiết bị đầu cuối kiểm soát quy trình [nếu quy trình chưa có].import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283Cờ chỉ ra rằng nếu tệp tồn tại và là một tệp thông thường và tệp được mở thành công để truy cập ghi, thì độ dài của tệp sẽ bị cắt ngắn thành 0.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
284Cờ cho biết dữ liệu sẽ được thêm vào cuối tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
285Cờ chỉ ra rằng việc mở sẽ thất bại nếu đường dẫn không phải là một thư mục.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
286Cờ cho biết quyền truy cập đọc vào hệ thống tệp sẽ không còn dẫn đến cập nhật thông tinimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 được liên kết với tệp. Cờ này chỉ khả dụng trên hệ điều hành Linux.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
288Cờ chỉ ra rằng việc mở sẽ thất bại nếu đường dẫn là một liên kết tượng trưng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
289Cờ cho biết tệp được mở cho I/O được đồng bộ hóa với các thao tác ghi đang chờ tính toàn vẹn của tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
290Cờ cho biết tệp được mở cho I/O được đồng bộ hóa với các thao tác ghi đang chờ tính toàn vẹn của dữ liệu.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
291Cờ chỉ ra để mở chính liên kết tượng trưng chứ không phải tài nguyên mà nó đang trỏ tới.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
292Khi được đặt, một nỗ lực sẽ được thực hiện để giảm thiểu hiệu ứng bộ nhớ đệm của tệp I/O.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
293Cờ cho biết mở tệp ở chế độ không chặn khi có thể.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
294Khi được đặt, ánh xạ tệp bộ nhớ được sử dụng để truy cập tệp. Cờ này chỉ khả dụng trên hệ điều hành Windows. Trên các hệ điều hành khác, cờ này bị bỏ quaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Windows, chỉ có
284,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
279,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
276,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
278,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
283,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
277 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
294Hằng số loại tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các hằng số sau đây được dùng với thuộc tính
48 của đối tượng để xác định loại tệpConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
304Bit mask được sử dụng để trích xuất mã loại tệp.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
305Hằng số loại tệp cho một tệp thông thường.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
306Hằng số loại tệp cho một thư mục.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
307Hằng số loại tệp cho tệp thiết bị định hướng ký tự.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
308Hằng số loại tệp cho tệp thiết bị hướng khối.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
309Hằng số loại tệp cho FIFO/đường ống.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
310Hằng số loại tệp cho một liên kết tượng trưng.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
311Hằng số loại tệp cho ổ cắmimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Windows, chỉ có
307,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
306,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
310,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
304 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
305Hằng số chế độ tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Các hằng số sau đây được dùng với thuộc tính
48 của đối tượng để xác định quyền truy cập đối với một tệpConstantDescriptionimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
318Chế độ tệp cho biết chủ sở hữu có thể đọc, ghi và thực thi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
319Chế độ tệp cho biết chủ sở hữu có thể đọc được.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
320Chế độ tệp cho biết chủ sở hữu có thể ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
321Chế độ tệp cho biết chủ sở hữu có thể thực thi được.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
322Chế độ tệp cho biết có thể đọc, ghi và thực thi theo nhóm.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
323Chế độ tệp cho biết có thể đọc được theo nhóm.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
324Chế độ tệp cho biết có thể ghi theo nhóm.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
325Chế độ tệp cho biết có thể thực thi theo nhóm.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
326Chế độ tệp cho biết người khác có thể đọc, ghi và thực thi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
327Chế độ tệp cho biết người khác có thể đọc được.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
328Chế độ tệp cho biết người khác có thể ghi.import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
329Chế độ tệp cho biết người khác có thể thực thi đượcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Windows, chỉ có
319 vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
320import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
ghi chú
Thứ tự gọi lại và các hoạt động dựa trên lời hứa
Bởi vì chúng được thực thi không đồng bộ bởi nhóm luồng bên dưới, nên không có thứ tự được đảm bảo khi sử dụng phương pháp gọi lại hoặc dựa trên lời hứa
Ví dụ: phần sau dễ bị lỗi vì thao tác
330 có thể hoàn thành trước thao tácimport * as fs from 'node:fs';
const fs = require['node:fs'];
333import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
0import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Điều quan trọng là phải sắp xếp đúng thứ tự các thao tác bằng cách đợi kết quả của thao tác này trước khi gọi thao tác kia
1import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Hoặc, khi sử dụng API gọi lại, hãy di chuyển lệnh gọi
330 vào lệnh gọi lại của hoạt độngimport * as fs from 'node:fs';
const fs = require['node:fs'];
333import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
2import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đường dẫn tệp
Hầu hết các hoạt động của
56 chấp nhận đường dẫn tệp có thể được chỉ định ở dạng chuỗi, a hoặc đối tượng bằng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54Đường dẫn chuỗiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đường dẫn chuỗi được hiểu là chuỗi ký tự UTF-8 xác định tên tệp tuyệt đối hoặc tương đối. Đường dẫn tương đối sẽ được giải quyết liên quan đến thư mục làm việc hiện tại như được xác định bằng cách gọi
338import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Ví dụ sử dụng đường dẫn tuyệt đối trên POSIX
Ví dụ sử dụng đường dẫn tương đối trên POSIX [liên quan đến
338]Đường dẫn URL tệpimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Đối với hầu hết các hàm mô-đun
4, đối sốimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
47 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
12 có thể được truyền dưới dạng đối tượng bằng cách sử dụng giao thứcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
3import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 URL luôn là đường dẫn tuyệt đốiCân nhắc về nền tảng cụ thểimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Trên Windows,
54 s với tên máy chủ chuyển đổi thành đường dẫn UNC, trong khiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 s với ký tự ổ đĩa chuyển đổi thành đường dẫn tuyệt đối cục bộ.import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 s không có tên máy chủ và không có ký tự ổ đĩa sẽ dẫn đến lỗiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
54 s với ký tự ổ đĩa phải sử dụngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
349 làm dấu phân cách ngay sau ký tự ổ đĩa. Sử dụng dấu phân cách khác sẽ dẫn đến lỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên tất cả các nền tảng khác,
54 s có tên máy chủ không được hỗ trợ và sẽ gây ra lỗiimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Một
54 có các ký tự gạch chéo được mã hóa sẽ dẫn đến lỗi trên tất cả các nền tảngimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Trên Windows,
54 s có dấu gạch chéo ngược được mã hóa sẽ dẫn đến lỗiđường dẫn bộ đệmimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Đường dẫn được chỉ định bằng cách sử dụng a chủ yếu hữu ích trên một số hệ điều hành POSIX coi đường dẫn tệp là chuỗi byte mờ. Trên các hệ thống như vậy, một đường dẫn tệp duy nhất có thể chứa các chuỗi con sử dụng nhiều mã hóa ký tự. Như với đường dẫn chuỗi, đường dẫn có thể là tương đối hoặc tuyệt đối
Ví dụ sử dụng đường dẫn tuyệt đối trên POSIX
Thư mục làm việc trên mỗi ổ đĩa trên WindowsTrên Windows, nút. js tuân theo khái niệm thư mục làm việc trên mỗi ổ đĩa. Hành vi này có thể được quan sát thấy khi sử dụng đường dẫn ổ đĩa không có dấu gạch chéo ngược. Ví dụ:
353 có khả năng trả về một kết quả khác vớiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
354. Để biết thêm thông tin, xemimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
bộ mô tả tệp
Trên các hệ thống POSIX, đối với mọi quy trình, kernel duy trì một bảng các tệp và tài nguyên hiện đang mở. Mỗi tệp đang mở được gán một mã định danh số đơn giản được gọi là bộ mô tả tệp. Ở cấp hệ thống, tất cả các hoạt động của hệ thống tệp đều sử dụng các bộ mô tả tệp này để xác định và theo dõi từng tệp cụ thể. Các hệ thống Windows sử dụng một cơ chế khác nhưng tương tự về mặt khái niệm để theo dõi tài nguyên. Để đơn giản hóa mọi thứ cho người dùng, Node. js trừu tượng hóa sự khác biệt giữa các hệ điều hành và gán cho tất cả các tệp đang mở một bộ mô tả tệp số
Các phương thức
64 dựa trên gọi lại vàimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
93 đồng bộ mở một tệp và phân bổ một bộ mô tả tệp mới. Sau khi được phân bổ, bộ mô tả tệp có thể được sử dụng để đọc dữ liệu, ghi dữ liệu vào hoặc yêu cầu thông tin về tệpimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
Hệ điều hành giới hạn số lượng bộ mô tả tệp có thể được mở tại bất kỳ thời điểm nào, do đó, điều quan trọng là phải đóng bộ mô tả khi hoàn thành các thao tác. Không làm như vậy sẽ dẫn đến rò rỉ bộ nhớ, cuối cùng sẽ khiến ứng dụng bị sập
Các API dựa trên lời hứa sử dụng một đối tượng thay cho bộ mô tả tệp số. Các đối tượng này được hệ thống quản lý tốt hơn đảm bảo tài nguyên không bị rò rỉ. Tuy nhiên, chúng vẫn được yêu cầu đóng lại khi hoạt động hoàn tất
sử dụng threadpool
Tất cả API hệ thống tệp gọi lại và dựa trên lời hứa [ngoại trừ
357] đều sử dụng nhóm luồng của libuv. Điều này có thể có ý nghĩa hiệu suất đáng ngạc nhiên và tiêu cực đối với một số ứng dụng. Xem tài liệu để cho biết thêm thông tin chi tiếtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Cờ hệ thống tập tin
Các cờ sau có sẵn ở bất cứ nơi nào tùy chọn
359 lấy một chuỗiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
360. Mở tệp để nối thêm. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
361. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
360 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
363. Mở tệp để đọc và nối thêm. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
364. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
363 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
366. Mở tệp để nối thêm ở chế độ đồng bộ. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
367. Mở tệp để đọc và nối thêm ở chế độ đồng bộ. Tệp được tạo nếu nó không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
57. Mở tệp để đọc. Một ngoại lệ xảy ra nếu tệp không tồn tạiimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
369. Mở tệp để đọc và ghi. Một ngoại lệ xảy ra nếu tệp không tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
370. Mở tệp để đọc và ghi ở chế độ đồng bộ. Hướng dẫn hệ điều hành bỏ qua bộ đệm ẩn của hệ thống tệp cục bộimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Điều này chủ yếu hữu ích để mở các tệp trên các ngàm NFS vì nó cho phép bỏ qua bộ đệm cục bộ có khả năng cũ. Nó có tác động rất thực đến hiệu năng I/O nên không nên sử dụng cờ này trừ khi cần thiết
Điều này không biến
64 hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
03 thành cuộc gọi chặn đồng bộ. Nếu muốn hoạt động đồng bộ, nên sử dụng một cái gì đó nhưimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
93import { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
374. Mở tệp để viết. Tệp được tạo [nếu không tồn tại] hoặc bị cắt bớt [nếu tồn tại]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
375. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
374 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
377. Mở tệp để đọc và ghi. Tệp được tạo [nếu không tồn tại] hoặc bị cắt bớt [nếu tồn tại]import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
378. Giống nhưimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
377 nhưng không thành công nếu đường dẫn tồn tạiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
359 cũng có thể là một số như được ghi lại bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
58; . Trên Windows, các cờ được dịch sang các cờ tương đương nếu có, ví dụ:. g.import { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
277 đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
384, hoặcimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
385 đếnimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
386, như được chấp nhận bởiimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
387import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Cờ độc quyền
388 [cờimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
280 trongimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
58] khiến thao tác trả về lỗi nếu đường dẫn đã tồn tại. Trên POSIX, nếu đường dẫn là một liên kết tượng trưng, việc sử dụngimport { unlink } from 'node:fs'; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
const { unlink } = require['node:fs']; unlink['/tmp/hello', [err] => { if [err] throw err; console.log['successfully deleted /tmp/hello']; }];
280 sẽ trả về lỗi ngay cả khi liên kết đến một đường dẫn không tồn tại. Cờ độc quyền có thể không hoạt động với hệ thống tệp mạngimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Trên Linux, chức năng ghi theo vị trí không hoạt động khi tệp được mở ở chế độ chắp thêm. Hạt nhân bỏ qua đối số vị trí và luôn nối thêm dữ liệu vào cuối tệp
Sửa đổi một tệp thay vì thay thế nó có thể yêu cầu tùy chọn
359 được đặt thànhimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
369 thay vì mặc định làimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
374import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Hành vi của một số cờ là dành riêng cho nền tảng. Như vậy, việc mở một thư mục trên macOS và Linux bằng cờ
363, như trong ví dụ bên dưới, sẽ trả về lỗi. Ngược lại, trên Windows và FreeBSD, một bộ mô tả tệp hoặc mộtimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
02 sẽ được trả vềimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
Trên Windows, mở một tệp ẩn hiện có bằng cờ
374 [thông quaimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
64,import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
76 hoặcimport { open } from 'node:fs/promises'; const fd = await open['sample.txt']; fd.createReadStream[{ start: 90, end: 99 }];
03] sẽ không thành công vớiimport * as fs from 'node:fs/promises';
const fs = require['node:fs/promises'];
228. Các tệp ẩn hiện có có thể được mở để ghi bằng cờimport { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
369import { unlink } from 'node:fs/promises'; try { await unlink['/tmp/hello']; console.log['successfully deleted /tmp/hello']; } catch [error] { console.error['there was an error:', error.message]; }
const { unlink } = require['node:fs/promises']; [async function[path] { try { await unlink[path]; console.log[`successfully deleted ${path}`]; } catch [error] { console.error['there was an error:', error.message]; } }]['/tmp/hello'];
Làm cách nào để đọc tệp đầu vào trong JavaScript?
Để đọc tệp, sử dụng FileReader , cho phép bạn đọc nội dung của đối tượng Tệp vào bộ nhớ. Bạn có thể hướng dẫn FileReader đọc tệp dưới dạng bộ đệm mảng, URL dữ liệu hoặc văn bản. // Kiểm tra xem file có phải là ảnh không.Có thể xử lý tệp trong JavaScript không?
Xử lý tệp trong JavaScript là một kỹ thuật trong đó tệp được viết ở định dạng html bằng cách sử dụng CSS có thể được gọi bằng cách sử dụng tệp html bên ngoài hoặc sử dụng. tệp js trỏ đến tệp html đó . Thao tác xử lý tệp trong JavaScript bao gồm mở tệp, đóng tệp, Cập nhật dữ liệu trong tệp.Làm cách nào để tải một tệp trong JavaScript?
Để tải động tệp JavaScript. .Tạo phần tử tập lệnhĐặt các thuộc tính src , async và typeNối phần tử tập lệnh vào phần thânKiểm tra xem tệp có được tải hay không trong sự kiện tảiLàm cách nào để đọc một tệp trong JavaScript theo từng dòng?
Trong JavaScript, phương thức tích hợp sẵn FileReader[] cùng với mô-đun readline có thể được sử dụng để đọc từng dòng tệp . Phương thức FileReader[] đọc nội dung của các tệp được lưu trữ trên hệ thống cục bộ. Hơn nữa, mô-đun readline thực hiện việc đọc nội dung. Cả hai phương pháp này đều yêu cầu nguồn của tệp.