Properly use `Blob.slice` for reading chunk data

Rant time, why the hell does is the `end` parameter of `Blob.slice(start, end)` the index of the first byte **not** included? Why does this API go against almost every other stream API out there?
dashboard
Pat Hartl 2023-01-02 16:11:43 -06:00
parent a8bbd8623b
commit 024eec1b50
3 changed files with 3 additions and 3 deletions

View File

@ -42,7 +42,7 @@ class Uploader {
this.GetChunks(); this.GetChunks();
for (let chunk of this.Chunks) { for (let chunk of this.Chunks) {
let formData = new FormData(); let formData = new FormData();
formData.append('file', this.File.slice(chunk.Start, chunk.End)); formData.append('file', this.File.slice(chunk.Start, chunk.End + 1));
formData.append('start', chunk.Start.toString()); formData.append('start', chunk.Start.toString());
formData.append('end', chunk.End.toString()); formData.append('end', chunk.End.toString());
formData.append('key', this.Key); formData.append('key', this.Key);

View File

@ -1 +1 @@
{"version":3,"file":"Upload.js","sourceRoot":"","sources":["Upload.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,KAAK;IAKP,YAAY,KAAa,EAAE,GAAW,EAAE,KAAa;QACjD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACvB,CAAC;CACJ;AAED,MAAM,QAAQ;IAAd;QAKI,cAAS,GAAW,cAAc,CAAC;QACnC,eAAU,GAAW,eAAe,CAAC;QAErC,iBAAY,GAAW,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;IAoF5C,CAAC;IA7EG,IAAI,CAAC,SAAiB;QAClB,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAqB,CAAC;QACxE,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;QAEjD,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QAEjB,IAAI,CAAC,UAAU,CAAC,QAAQ,GAAG,CAAO,CAAC,EAAE,EAAE;YACnC,MAAM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AI,EAAE,QAAQ;qBACjB,CAAC,CAAC;oBAEH,QAAQ,CAAC;iBACZ;aACJ;QACL,CAAC;KAAA;IAED,SAAS;QACL,KAAK,IAAI,YAAY,GAAG,CAAC,EAAE,YAAY,IAAI,IAAI,CAAC,WAAW,EAAE,YAAY,EAAE,EAAE;YACzE,IAAI,KAAK,GAAG,CAAC,YAAY,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC;YACnD,IAAI,GAAG,GAAG,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAEjD,IAAI,YAAY,IAAI,IAAI,CAAC,WAAW;gBAChC,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;YAEzB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,GAAG,EAAE,YAAY,CAAC,CAAC,CAAC;SACzD;IACL,CAAC;CACJ"}

View File

@ -56,7 +56,7 @@ class Uploader {
for (let chunk of this.Chunks) { for (let chunk of this.Chunks) {
let formData = new FormData(); let formData = new FormData();
formData.append('file', this.File.slice(chunk.Start, chunk.End)); formData.append('file', this.File.slice(chunk.Start, chunk.End + 1));
formData.append('start', chunk.Start.toString()); formData.append('start', chunk.Start.toString());
formData.append('end', chunk.End.toString()); formData.append('end', chunk.End.toString());
formData.append('key', this.Key); formData.append('key', this.Key);