Theme
Types and constants Preview
DirListItem
The one shape returned by every listing and stat operation, local, virtual and remote alike.
ts
{
Name: string, // see the note below
Type: string, // "FILE" or "DIR"
Size: number, // bytes; 0 for a directory on most backends
TimeStamp: <engine timestamp> // NOT a JavaScript Date
}Where it comes from:
| Source | Returns |
|---|---|
ListDir, ListDirR | An array, Name is the full path |
StatFileSystemObject | One item, Name is the bare name. Empty item when the path does not exist |
vfs.ReadDir().Infos() | An array |
vfs.Stat().Info() | One item |
| Remote client listings | An array. Stat returns null when the object is missing |
Name is a full path in some places and a bare name in others
ListDir and ListDirR give you /var/inbox/report.csv. StatFileSystemObject gives you report.csv. Normalize with ExtractName() and ExtractPath() rather than assuming.
TimeStamp is not a JavaScript Date
It has no getTime() and no toISOString(). Pass it to ToDate() for a real Date, or straight to FormatDateTime() for a formatted string.
js
var when = ToDate(item.TimeStamp);
Log.Info(FormatDateTime("YYYY-MM-DD HH:mm:ss", item.TimeStamp));Iterating is ordinary JavaScript:
js
var items = ListDir("/var/inbox", "*.csv");
if (Array.isArray(items)) {
items.forEach(function (item) {
Log.Info(item.Name + " [" + item.Type + "] " + item.Size + " bytes");
});
}VFS response types
Every virtual file system method returns one of six response objects, all of which carry Ok(), ErrorMsg() and Error(). They are described on The virtual file system object.
Virtual file system types
Used as the first argument to new VirtualFS(...).
| Constant | Value | Storage |
|---|---|---|
VfsTypeDisk | "Disk" | Local disk, network path or UNC share |
VfsTypeS3 | "S3" | Amazon S3 and S3 compatible services |
VfsTypeAzure | "Azure" | Azure Blob Storage |
VfsTypeGCS | "GCP" | Google Cloud Storage |
VfsTypeSFTP | "SFTP" | A remote SFTP server |
VfsTypeR2FS | "R2FS" | Defined, but cannot be constructed on the Connector |
Note that VfsTypeGCS has the value "GCP", not "GCS". Use the constant and the discrepancy never matters.
Sorting a listing
Used as the second and third arguments to vfs.ReadDir().
| Constant | Value | Sorts by |
|---|---|---|
SortByName | "name" | Name, alphabetically |
SortByNameDirsFirst | "namedf" | Name, with folders first. The fallback |
SortBySize | "size" | Size |
SortByTime | "time" | Modification time |
| Constant | Value | Direction |
|---|---|---|
SortAsc | "asc" | Ascending. The fallback |
SortDesc | "desc" | Descending |
An unrecognized value is not an error; it falls back to SortByNameDirsFirst and SortAsc.
Seek origins
Used as the whence argument when reading and writing files through a virtual file system.
| Constant | Value | offset is measured from |
|---|---|---|
FromStart | 0 | The beginning of the file |
FromCurrent | 1 | The current position |
FromEnd | 2 | The end of the file |
0, FromStart overwrites from the beginning. 0, FromEnd appends.
Transfer policy
Used with remote clients, on cli.Options.UploadPolicy and cli.Options.DownloadPolicy.
| Constant | Value | When the destination exists |
|---|---|---|
NeverOverwrite | 0 | Skip it. The default |
AlwaysOverwrite | 1 | Replace it |
OverwriteIfDiffSize | 2 | Replace it only when the sizes differ |
OverwriteIfNewer | 3 | Replace it only when the source is newer |
On the fly encryption
Used on cli.Options.OTFEAlgorithm.
| Constant | Value | Algorithm |
|---|---|---|
OTFEAlgoAES256GCM | 0 | AES-256-GCM with PBKDF2-SHA256 key derivation. The default |
OTFEAlgoOpenPGP | 1 | OpenPGP symmetric passphrase encryption, RFC 4880 |
FTP and FTPS
Used on FtpsClient.
| Constant | Value | Meaning |
|---|---|---|
TLS_MODE_NONE | 0 | Plain FTP, no encryption |
TLS_MODE_EXPLICIT | 1 | Starts plain, upgrades with AUTH TLS |
TLS_MODE_IMPLICIT | 2 | TLS from the first byte, normally port 990 |
| Constant | Value | Transfer type |
|---|---|---|
FTP_MODE_I | "I" | Binary. The default after Connect() |
FTP_MODE_A | "A" | ASCII, with line ending translation |
Listing filters
Used as the types argument to a remote client's ListDir and ListDirR.
| Constant | Value | Returns |
|---|---|---|
LIST_ALL | 0 | Files and folders |
LIST_FILES | 1 | Files only |
LIST_DIRS | 2 | Folders only |