Skip to content

Commit 2711b47

Browse files
Merge pull request #428 from appwrite/fix-deno-chunk-upload
Fix: Deno Chunk Upload
2 parents 7b03d75 + aff50d2 commit 2711b47

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

templates/deno/src/services/service.ts.twig

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ export class {{ service.name | caseUcfirst }} extends Service {
135135
headers['x-{{spec.title | caseLower }}-id'] = id;
136136
}
137137

138-
const totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
138+
let totalBuffer = new Uint8Array(Client.CHUNK_SIZE);
139+
let lastBufferIndex = -1;
139140

140141
for (let blockIndex = 0; blockIndex < Client.CHUNK_SIZE / Client.DENO_READ_CHUNK_SIZE; blockIndex++) {
141142
const buf = new Uint8Array(Client.DENO_READ_CHUNK_SIZE);
@@ -148,7 +149,20 @@ export class {{ service.name | caseUcfirst }} extends Service {
148149

149150
for (let byteIndex = 0; byteIndex < Client.DENO_READ_CHUNK_SIZE; byteIndex++) {
150151
totalBuffer[(blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex] = buf[byteIndex];
152+
153+
if(buf[byteIndex] !== 0) {
154+
lastBufferIndex = (blockIndex * Client.DENO_READ_CHUNK_SIZE) + byteIndex;
155+
}
156+
}
157+
}
158+
159+
// Shrink empty bytes
160+
if(lastBufferIndex !== -1) {
161+
const newTotalBuffer = new Uint8Array(lastBufferIndex + 1);
162+
for(let index = 0; index <= lastBufferIndex; index++) {
163+
newTotalBuffer[index] = totalBuffer[index];
151164
}
165+
totalBuffer = newTotalBuffer;
152166
}
153167

154168
payload['{{ parameter.name }}'] = new File([totalBuffer], basename({{ parameter.name | caseCamel | escapeKeyword }}));

0 commit comments

Comments
 (0)