Skip to content

Commit 92f453b

Browse files
committed
docs: adding cache related function to readme
1 parent 5aec3d5 commit 92f453b

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

packages/hub/README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,51 @@ Checkout the demo: https://huggingface.co/spaces/huggingfacejs/client-side-oauth
117117

118118
The `@huggingface/hub` package provide basic capabilities to scan the cache directory. Learn more about [Manage huggingface_hub cache-system](https://huggingface.co/docs/huggingface_hub/en/guides/manage-cache).
119119

120+
### `scanCacheDir`
121+
122+
You can get the list of cached repository using the `scanCacheDir` function.
123+
120124
```ts
121125
import { scanCacheDir } from "@huggingface/hub";
122126

123127
const result = await scanCacheDir();
124128

125129
console.log(result);
126130
```
127-
Note that the cache directory is created and used only by the Python and Rust libraries. Downloading files using the `@huggingface/hub` package won't use the cache directory.
131+
Note: this does not work in the browser
132+
133+
### `downloadFileToCacheDir`
134+
135+
You can cache a file of a repository using the `downloadFileToCacheDir` function.
136+
137+
```ts
138+
import { snapshotDownload } from "@huggingface/hub";
139+
140+
const file = await downloadFileToCacheDir({
141+
repo: 'foo/bar',
142+
path: 'README.md'
143+
});
144+
145+
console.log(file);
146+
```
147+
Note: this does not work in the browser
148+
149+
### `snapshotDownload`
150+
151+
You can download an entire repository at a given revision in the cache directory using the `snapshotDownload` function.
152+
153+
```ts
154+
import { snapshotDownload } from "@huggingface/hub";
155+
156+
const directory = await snapshotDownload({
157+
repo: 'foo/bar',
158+
});
159+
160+
console.log(directory);
161+
```
162+
The code use internally the `downloadFileToCacheDir` function.
163+
164+
Note: this does not work in the browser
128165

129166
## Performance considerations
130167

0 commit comments

Comments
 (0)