Commit 4e37f8e
Alan Shaw
feat: custom chunk size (#2396)
Since we upped the default chunk size, folks uploading directories with
thousands of small files are sometimes finding the worker exceeds
resource limits 🤦♂️. This allows them to `encodeDirectory` and then
`storeCar` with a smaller chunk size to allow the directory to upload
successfully.
e.g.
```js
import { NFTStorage } from 'nft.storage'
import { filesFromPaths } from 'files-from-path'
const token = 'API_KEY' // your API key from https://nft.storage/manage
async function main() {
const storage = new NFTStorage({ token })
const files = await filesFromPaths(['/path/to/files'])
const { cid, car } = await NFTStorage.encodeDirectory(files)
console.log(`File CID: ${cid}`)
console.log('Sending file...')
await storage.storeCar(car, {
maxChunkSize: 1024 * 1024 * 10, // 10MB
onStoredChunk: (size) => console.log(`Stored a chunk of ${size} bytes`)
})
console.log('✅ Done')
}
main()
```1 parent a9e0a24 commit 4e37f8e
3 files changed
Lines changed: 29 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
153 | 157 | | |
154 | 158 | | |
155 | 159 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
198 | 221 | | |
199 | 222 | | |
200 | 223 | | |
| |||
0 commit comments