Kuba

3 Beiträge • 2 Abonnenten • 43 Ansichten
Jakub Kaniewski
 veröffentlicht vor 4 Monaten

Test

Jakub Kaniewski
 veröffentlicht vor 4 Monaten
Test


Test

Luan Trasel
 veröffentlicht vor 3 Monaten
1

test

Jakub Kaniewski
 veröffentlicht vor 2 Wochen  Bearbeitet

Bold
Italic

Underline
URL


  • 1
  • 2
  • 3


  1. a
  2. b
  3. c
export async function main() {
console.log('Running scheduled app')

const part1 = new Uint8Array(5 * 1024 * 1024)
const part2 = new Uint8Array([1, 2, 3, 4, 5])

part1.fill(97) // "a"

async function* fileStream() {
yield part1
yield part2
}

const file = await storage.uploadStream(fileStream(), {
contentType: 'application/octet-stream',
expiresInSeconds: 3600,
contentDisposition: 'attachment; filename="multipart-test.bin"',
})

const response = await fetch(file.url)
if (!response.ok) {
throw new Error(`Download failed with ${response.status} ${response.statusText}`)
}

const downloaded = new Uint8Array(await response.arrayBuffer())
const expectedLength = part1.byteLength + part2.byteLength

if (downloaded.byteLength !== expectedLength) {
throw new Error(`Wrong size: got ${downloaded.byteLength}, expected ${expectedLength}`)
}

for (let index = 0; index < part1.byteLength; index += 1) {
if (downloaded[inde😆 !== part1[index]) {
throw new Error(`Part 1 mismatch at byte ${index}`)
}
}

for (let index = 0; index < part2.byteLength; index += 1) {
const downloadedIndex = part1.byteLength + index
if (downloaded[downloadedInde😆 !== part2[index]) {
throw new Error(`Part 2 mismatch at byte ${downloadedIndex}`)
}
}

console.log({
id: file.id,
url: file.url,
bytes: downloaded.byteLength,
ok: true,
})
}