* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key * @param {import('../../types/cache-interceptor.d.ts').default.CacheValue} value * @returns {Writable | undefined}
(key, value)
| 310 | * @returns {Writable | undefined} |
| 311 | */ |
| 312 | createWriteStream (key, value) { |
| 313 | assertCacheKey(key) |
| 314 | assertCacheValue(value) |
| 315 | |
| 316 | let size = 0 |
| 317 | /** |
| 318 | * @type {Buffer[] | null} |
| 319 | */ |
| 320 | const body = [] |
| 321 | const store = this |
| 322 | |
| 323 | return new Writable({ |
| 324 | decodeStrings: true, |
| 325 | write (chunk, encoding, callback) { |
| 326 | size += chunk.byteLength |
| 327 | |
| 328 | if (size <= store.#maxEntrySize) { |
| 329 | body.push(chunk) |
| 330 | } else { |
| 331 | this.destroy() |
| 332 | } |
| 333 | |
| 334 | callback() |
| 335 | }, |
| 336 | final (callback) { |
| 337 | store.set(key, { ...value, body }) |
| 338 | callback() |
| 339 | } |
| 340 | }) |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key |
nothing calls this directly
no test coverage detected