File Storage Agent
import { FileStorageAgent } from "@fstnetwork/loc-logic-sdk";
Accessing and writing files. Supports the following storages:
- FTP (File Transfer Protocol)
- Amazon S3
- SMB (Server Message Block)
Availability
- ✓ Generic logic
- ✗ Aggregator logic
This agent requires agent configuration. See tutorial or CLI Handbook for details.
Acquire File Client
async FileStorageAgent.acquire(configurationName: string): Promise<FileStorageAgentClient>
Returns a FileStorageAgentClient
object based on provided agent configuration name, which connects to a pre-defined file storage with confidential information (if needed).
The configuration name is the reference
field set in Studio or name
field set in CLI config files.
Throws an error if the configuration cannot be found.
Example
const fileClient = await FileStorageAgent.acquire("my-file-configuration");
File Storage Client
Read from File Storage
async fileClient.simpleGet(path: string): Promise<Uint8Array>
Read a remote file.
Parameter | Type | Description |
---|---|---|
path | string | File path (no / prefix) |
Example
const path = "dir/test.txt";
const fileClient = await FileStorageAgent.acquire("my-file-configuration");
// get file
const file = await fileClient?.simpleGet(path);
// decode file to string
const data = new TextDecoder().decode(file);
Write to File Storage
async fileClient.simplePut(path: string, data: Uint8Array | string, options?: FileStorage.PutOptions): Promise<number>
Write a file to remote storage.
Parameter | Type | Description |
---|---|---|
path | string | File path (no / prefix) |
data | Uint8Array | string | File content |
options | FileStorage.PutOptions , which is { ensureDir?: boolean; } | (Optional) For SMB |
Example
// data
const path = "dir/test.txt";
const data = `Hello World!
This is line two`;
// write to file storage
await fileClient?.simplePut(path, data);
Example using options
await fileClient.simplePut(path, data, { ensureDir: true });
Delete File
async fileClient.delete(path: string): Promise<void>
Delete a file from file storage.
Create Directory
async fileClient.createDirAll(path: string): Promise<void>
Create a directory at a remote path.
List Directories and Files
async fileClient.list(path: string): Promise<Array<FileStorage.FileType>>
List directories and files at a remote path.
Returns an array of type FileStorage.FileType
. A FileType
object has two fields:
Fields | Type | Description |
---|---|---|
name | string | Item name |
type | "file" | "directory" | "symbolicLink" | Item type |
The type indicates that an item is a file, a directory or a symbolic link (in SMB).
Example
const fileList = await fileClient?.list(path);
// iterate through all items in the list
fileList.forEach((item) => {
const name = item.name; // get name
const type = item.type; // get type
// ...
});