-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into W-16440795-never-remap-set-and-map
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
test/membrane/untrusted/binary-data/FileSaver-blue-blob.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function blueBlobToRedBlob(blueBlob) { | ||
const reader = blueBlob.stream().getReader(); | ||
let result = new Uint8Array(0); | ||
let resolve, reject; | ||
const promise = new Promise((_resolve, _reject) => { | ||
resolve = _resolve; | ||
reject = _reject; | ||
}); | ||
const handler = ({ done, value }) => { | ||
try { | ||
if (done) { | ||
const redBlob = new Blob([result.buffer], { type: blueBlob.type }); | ||
resolve(redBlob); | ||
return; | ||
} | ||
const merge = new Uint8Array(result.length + value.length); | ||
merge.set(result); | ||
merge.set(value, result.length); | ||
result = merge; | ||
return reader.read().then(handler, reject); | ||
} catch (e) { | ||
reject(e); | ||
} | ||
}; | ||
reader.read().then(handler, reject); | ||
return promise; | ||
} | ||
|
||
const blueBlob = getBlueBlob(); | ||
|
||
const blobToSavePromise = transferBlueBlob | ||
? blueBlobToRedBlob(blueBlob) | ||
: Promise.resolve(blueBlob); | ||
|
||
blobToSavePromise.then((blobToSave) => { | ||
if (expectedToThrow) { | ||
expect(() => { | ||
saveAs(blobToSave, 'blue-binary.txt'); | ||
}).toThrow(); | ||
} else { | ||
expect(() => { | ||
saveAs(blobToSave, 'blue-binary.txt'); | ||
}).not.toThrow(); | ||
} | ||
done(); | ||
}); |