Skip to content

file-storage v0.6.0

Compare
Choose a tag to compare
@github-actions github-actions released this 04 Feb 01:41
· 19 commits to main since this release
  • BREAKING CHANGE: LocalFileStorage now uses 2 characters for shard directory names instead of 8.
  • Buffer contents of files stored in MemoryFileStorage.
  • Add storage.list(options) for listing files in storage.

The following options are available:

  • cursor: An opaque string that allows you to paginate over the keys in storage
  • includeMetadata: If true, include file metadata in the result
  • limit: The maximum number of files to return
  • prefix: Only return keys that start with this string

For example, to list all files under keys that start with user123/:

let result = await storage.list({ prefix: 'user123/' });
console.log(result.files);
// [
//   { key: "user123/..." },
//   { key: "user123/..." },
//   ...
// ]

result.files will be an array of { key: string } objects. To include metadata about each file, use includeMetadata: true.

let result = await storage.list({ prefix: 'user123/', includeMetadata: true });
console.log(result.files);
// [
//   {
//     key: "user123/...",
//     lastModified: 1737955705270,
//     name: "hello.txt",
//     size: 16,
//     type: "text/plain"
//   },
//   ...
// ]

Pagination is done via an opaque cursor property in the list result object. If it is not undefined, there are more files to list. You can list them by passing the cursor back in the options object on the next call. For example, to list all items in storage, you could do something like this:

let result = await storage.list();
console.log(result.files);

while (result.cursor !== undefined) {
  result = await storage.list({ cursor: result.cursor });
  console.log(result.files);
}

Use the limit option to limit how many results you get back in the files array.