在不同的文件系统中工作

Node.js exposes many features of the filesystem. But not all filesystems are alike. The following are suggested best practices to keep your code simple and safe when working with different filesystems.

Node.js暴露了文件系统的许多功能。但不是所有的文件系统都是一样的。以下是建议的最佳做法,在使用不同的文件系统时,保持你的代码简单和安全。

Before you can work with a filesystem, you need to know how it behaves. Different filesystems behave differently and have more or less features than others: case sensitivity, case insensitivity, case preservation, Unicode form preservation, timestamp resolution, extended attributes, inodes, Unix permissions, alternate data streams etc.

在使用一个文件系统之前,你需要知道它的行为方式。不同的文件系统有不同的行为,并且比其他的文件系统有更多或更少的功能:大小写敏感性、大小写不敏感性、大小写保存、Unicode形式保存、时间戳解析、扩展属性、inodes、Unix权限、备用数据流等等。

Be wary of inferring filesystem behavior from process.platform. For example, do not assume that because your program is running on Darwin that you are therefore working on a case-insensitive filesystem (HFS+), as the user may be using a case-sensitive filesystem (HFSX). Similarly, do not assume that because your program is running on Linux that you are therefore working on a filesystem which supports Unix permissions and inodes, as you may be on a particular external drive, USB or network drive which does not.

对从process.platform 推断文件系统的行为要保持警惕。例如,不要因为你的程序在Darwin上运行就认为你是在一个不区分大小写的文件系统(HFS+)上工作,因为用户可能正在使用一个区分大小写的文件系统(HFSX)。同样,不要认为你的程序在Linux上运行,你就在一个支持Unix权限和节点的文件系统上工作,因为你可能在一个特定的外部驱动器、USB或网络驱动器上不支持。

The operating system may not make it easy to infer filesystem behavior, but all is not lost. Instead of keeping a list of every known filesystem and behavior (which is always going to be incomplete), you can probe the filesystem to see how it actually behaves. The presence or absence of certain features which are easy to probe, are often enough to infer the behavior of other features which are more difficult to probe.

操作系统可能不容易推断出文件系统的行为,但一切并没有失去。与其保留一份每个已知文件系统和行为的清单(它总是不完整的),你可以探测文件系统,看看它实际上是如何行为的。某些容易探测的特性的存在或不存在,往往足以推断出其他更难探测的特性的行为。

Remember that some users may have different filesystems mounted...

开通本站会员,查看完整译文。

trang chủ - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.3. UTC+08:00, 2024-11-28 22:01
浙ICP备14020137号-1 $bản đồ khách truy cập$