Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Blob #31

Merged
merged 1 commit into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ The following object types are deeply cloned when they are either properties on

- `Array`
- `ArrayBuffer`
- `Blob`
- `Buffer`
- `DataView`
- `Date`
Expand Down
2 changes: 2 additions & 0 deletions __tests__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const COMPLEX_TYPES: PlainObject = {
object: { foo: { bar: 'baz' } },
regexp: /foo/,
set: new Set().add('foo').add({ bar: { baz: 'quz' } }),
blob: new Blob(['<a id="a">hey!</a>'], {type : 'text/html'}),
uint8Array: new Uint8Array([12, 15]),
uint8ClampedArray: new Uint8ClampedArray([12, 15]),
uint16Array: new Uint16Array([12, 15]),
Expand Down Expand Up @@ -240,6 +241,7 @@ describe('copy', () => {
Map: global.Map,
RegExp: global.RegExp,
Set: global.Set,
Blob: global.Blob,
WeakMap: global.WeakMap,
WeakSet: global.WeakSet,
};
Expand Down
6 changes: 6 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ function copy<T>(object: T, options?: FastCopy.Options): T {
return clone;
}

// blobs
if (realm.Blob && object instanceof realm.Blob) {
clone = new Blob([object], { type: object.type });
return clone
}

// buffers (node-only)
if (realm.Buffer && realm.Buffer.isBuffer(object)) {
clone = realm.Buffer.allocUnsafe
Expand Down