|
@@ -70,23 +70,41 @@ export async function serverFetchBlob<T>(...args: FetchParams) { |
|
|
let finalUInt8Array = new Uint8Array() |
|
|
let finalUInt8Array = new Uint8Array() |
|
|
let done = false |
|
|
let done = false |
|
|
|
|
|
|
|
|
// Read some more, and call this function again |
|
|
|
|
|
while (!done) { |
|
|
while (!done) { |
|
|
// Result objects contain two properties: |
|
|
|
|
|
// done - true if the stream has already given you all its data. |
|
|
|
|
|
// value - some data. Always undefined when done is true. |
|
|
|
|
|
const read = await reader?.read() |
|
|
const read = await reader?.read() |
|
|
|
|
|
|
|
|
|
|
|
// version 1 |
|
|
if (read?.done) { |
|
|
if (read?.done) { |
|
|
done = true |
|
|
done = true |
|
|
} else { |
|
|
} else { |
|
|
// value for fetch streams is a Uint8Array |
|
|
|
|
|
finalUInt8Array = new Uint8Array(read?.value.length!!) |
|
|
|
|
|
finalUInt8Array.set(read?.value!!) |
|
|
|
|
|
|
|
|
const tempUInt8Array = new Uint8Array(finalUInt8Array.length + read?.value.length!!) |
|
|
|
|
|
tempUInt8Array.set(finalUInt8Array) |
|
|
|
|
|
tempUInt8Array.set(read?.value!!, finalUInt8Array.length) |
|
|
|
|
|
finalUInt8Array = new Uint8Array(tempUInt8Array.length!!) |
|
|
|
|
|
finalUInt8Array.set(tempUInt8Array) |
|
|
|
|
|
|
|
|
|
|
|
// console.log("1", finalUInt8Array) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// const bodyRead = await reader?.read() |
|
|
|
|
|
|
|
|
// version 2 & return bodyRead |
|
|
|
|
|
// const bodyRead = reader?.read().then(function processText({ done, value }): any { |
|
|
|
|
|
// // Result objects contain two properties: |
|
|
|
|
|
// // done - true if the stream has already given you all its data. |
|
|
|
|
|
// // value - some data. Always undefined when done is true. |
|
|
|
|
|
// if (done) { |
|
|
|
|
|
// console.log("Stream complete"); |
|
|
|
|
|
// return { filename: response.headers.get("filename"), blobValue: finalUInt8Array } as T;; |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// // value for fetch streams is a Uint8Array |
|
|
|
|
|
// finalUInt8Array = new Uint8Array(value.length) |
|
|
|
|
|
// finalUInt8Array.set(value) |
|
|
|
|
|
|
|
|
|
|
|
// console.log(finalUInt8Array) |
|
|
|
|
|
// // Read some more, and call this function again |
|
|
|
|
|
// return reader.read().then(processText); |
|
|
|
|
|
// }) |
|
|
// const bodyValue = bodyRead?.value |
|
|
// const bodyValue = bodyRead?.value |
|
|
|
|
|
|
|
|
// const blob = await response.blob() |
|
|
// const blob = await response.blob() |
|
@@ -94,7 +112,7 @@ export async function serverFetchBlob<T>(...args: FetchParams) { |
|
|
// const blobType = await blob.type; |
|
|
// const blobType = await blob.type; |
|
|
|
|
|
|
|
|
// console.log(bodyReader) |
|
|
// console.log(bodyReader) |
|
|
// console.log(finalUInt8Array) |
|
|
|
|
|
|
|
|
// console.log("2", finalUInt8Array) |
|
|
// console.log(bodyValue) |
|
|
// console.log(bodyValue) |
|
|
|
|
|
|
|
|
return { filename: response.headers.get("filename"), blobValue: finalUInt8Array } as T; |
|
|
return { filename: response.headers.get("filename"), blobValue: finalUInt8Array } as T; |
|
|