Skip to content

Commit 4d2f3f9

Browse files
committed
refactor: use directories parameter
1 parent cb16e0f commit 4d2f3f9

File tree

4 files changed

+361
-12
lines changed

4 files changed

+361
-12
lines changed

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,60 @@ const { blobs } = await store.list({ prefix: 'some' })
284284
console.log(blobs)
285285
```
286286

287+
Optionally, you can choose to group blobs together under a common prefix and then browse them hierarchically when
288+
listing a store.
289+
290+
To do this, you must use the `/` character in your keys to separate keys into multiple levels.
291+
292+
Take the following list of keys as an example:
293+
294+
```
295+
cats/garfield.jpg
296+
cats/tom.jpg
297+
mice/jerry.jpg
298+
mice/mickey.jpg
299+
pink-panther.jpg
300+
```
301+
302+
By default, calling `store.list()` will return all five keys.
303+
304+
```javascript
305+
const { blobs } = await store.list()
306+
307+
// [
308+
// { etag: "etag1", key: "cats/garfield.jpg" },
309+
// { etag: "etag2", key: "cats/tom.jpg" },
310+
// { etag: "etag3", key: "mice/jerry.jpg" },
311+
// { etag: "etag4", key: "mice/mickey.jpg" },
312+
// { etag: "etag5", key: "pink-panther.jg" },
313+
// ]
314+
console.log(blobs)
315+
```
316+
317+
But if you want to list entries hierarchically, use the `directories` parameter.
318+
319+
```javascript
320+
const { blobs, directories } = await store.list({ directories: true })
321+
322+
// [ { etag: "etag1", key: "pink-panther.jpg" } ]
323+
console.log(blobs)
324+
325+
// [ "cats", "mice" ]
326+
console.log(directories)
327+
```
328+
329+
To drill down into a directory and get a list of its items, you can use the directory name as the `prefix` value.
330+
331+
```javascript
332+
const { blobs, directories } = await store.list({ prefix: 'mice/' })
333+
334+
// [ { etag: "etag3", key: "mice/jerry.jpg" }, { etag: "etag4", key: "mice/mickey.jpg" } ]
335+
console.log(blobs)
336+
337+
// [ ]
338+
console.log(directories)
339+
```
340+
287341
## Contributing
288342

289343
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or

src/backend/list.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export interface ListResponse {
22
blobs?: ListResponseBlob[]
3+
directories?: string[]
34
next_cursor?: string
45
}
56

0 commit comments

Comments
 (0)