Skip to content

Commit

Permalink
Merge pull request #174 from TonyBrobston/preserve-file-name
Browse files Browse the repository at this point in the history
fix: preserve file name on Blob
  • Loading branch information
TonyBrobston authored Oct 2, 2020
2 parents 79f7adb + 82b51bf commit 3d02fe6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/services/fileService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const create = (bytes: Uint8Array[], type: string, name: string): File|Blob => {
try {
return new File(bytes, name, {type});
} catch (error) {
return new Blob(bytes, {type});
const blob = new Blob(bytes, {type});
blob.name = name;
return blob;
}
};

Expand Down
3 changes: 3 additions & 0 deletions src/types/Blob.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
interface Blob {
name: string
}
12 changes: 10 additions & 2 deletions tests/services/fileService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,15 @@ describe('fileService', (): void => {
actualFile = fileService.create([bytes], type, name);
});

it('should create a blob with size', (): void => {
it('should create a file with name', (): void => {
expect(actualFile.name).toBe(name);
});

it('should create a file with size', (): void => {
expect(actualFile.size).toBe(bytes.toString().length);
});

it('should create a blob with type', (): void => {
it('should create a file with type', (): void => {
expect(actualFile.type).toBe(type);
});
});
Expand All @@ -96,6 +100,10 @@ describe('fileService', (): void => {
actualBlob = fileService.create([bytes], type, name);
});

it('should create a blob with name', (): void => {
expect(actualBlob.name).toBe(name);
});

it('should create a blob with size', (): void => {
expect(actualBlob.size).toBe(bytes.toString().length);
});
Expand Down

0 comments on commit 3d02fe6

Please sign in to comment.