mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-17 16:50:22 +00:00
- add support for remote uploads - add support for restore using golden-retriever - update examples - #6181 still persists --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Mikael Finstad <finstaden@gmail.com>
17 lines
527 B
TypeScript
17 lines
527 B
TypeScript
/**
|
|
* Generate random bytes using Web Crypto API.
|
|
* Web Crypto has a 65536 byte limit per getRandomValues call,
|
|
* so we chunk large requests.
|
|
*/
|
|
export function randomBytes(size: number) {
|
|
const buffer = new Uint8Array(size)
|
|
const maxChunk = 65536 // Web Crypto API limit
|
|
|
|
for (let offset = 0; offset < size; offset += maxChunk) {
|
|
const chunkSize = Math.min(maxChunk, size - offset)
|
|
const chunk = buffer.subarray(offset, offset + chunkSize)
|
|
globalThis.crypto.getRandomValues(chunk)
|
|
}
|
|
|
|
return buffer
|
|
}
|