Return empty a empty stream for zero sized blob (#86)
Return empty a empty stream for zero sized blob
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
Changelog
|
||||
=========
|
||||
|
||||
## next
|
||||
- Fixed a bug where in BlobDataItem when the file was empty (#86)
|
||||
|
||||
## v2.1.2
|
||||
- Fixed a bug where `start` in BlobDataItem was undefined (#85)
|
||||
|
||||
## v2.1.1
|
||||
- Add nullish values checking in Symbol.hasInstance (#82)
|
||||
- Add generated typings for from.js file (#80)
|
||||
|
||||
@@ -43,6 +43,10 @@ class BlobDataItem {
|
||||
throw new DOMException('The requested file could not be read, typically due to permission problems that have occurred after a reference to a file was acquired.', 'NotReadableError');
|
||||
}
|
||||
|
||||
if (!this.size) {
|
||||
return new Blob().stream();
|
||||
}
|
||||
|
||||
return createReadStream(this.path, {
|
||||
start: this.start,
|
||||
end: this.start + this.size - 1
|
||||
|
||||
@@ -172,6 +172,12 @@ test('Reading from the stream created by blobFrom', async t => {
|
||||
t.is(actual, expected);
|
||||
});
|
||||
|
||||
test('Reading empty blobs', async t => {
|
||||
const blob = blobFrom('./LICENSE').slice(0, 0);
|
||||
const actual = await blob.text();
|
||||
t.is(actual, '');
|
||||
});
|
||||
|
||||
test('Blob-ish class is an instance of Blob', t => {
|
||||
class File {
|
||||
stream() {}
|
||||
|
||||
Reference in New Issue
Block a user