Skip to content
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 apps/test-suite/TestModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function getTestModules() {

if (['android', 'ios'].includes(Platform.OS)) {
modules.push(require('./tests/FileSystemNext'));
modules.push(require('./tests/Blob'));
}

if (Platform.OS === 'android') {
Expand Down
1,204 changes: 1,204 additions & 0 deletions apps/test-suite/tests/Blob.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o/classes
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o/classes
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class Blob() : SharedObject() {
}

fun slice(start: Int, end: Int, contentType: String): Blob {
if (start >= end) {
return Blob(listOf(), contentType)
}
var i: Int = 0
val bps: MutableList<InternalBlobPart> = mutableListOf()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package expo.modules.blob

import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import kotlin.math.max
import kotlin.math.min

class BlobModule : Module() {
override fun definition() = ModuleDefinition {
Name("ExpoBlob")

Class(Blob::class) {
Constructor() { blobParts: List<BlobPart>, options: BlobOptionsBag? ->
Constructor() { blobParts: List<BlobPart>?, options: BlobOptionsBag? ->
val type = options?.type ?: DEFAULT_TYPE
val endings = options?.endings ?: EndingType.TRANSPARENT
Blob(blobParts.internal(endings == EndingType.NATIVE), type)
Blob((blobParts ?: listOf()).internal(endings == EndingType.NATIVE), type)
}

Property("size") { blob: Blob ->
Expand All @@ -24,12 +26,16 @@ class BlobModule : Module() {

Function("slice") { blob: Blob, start: Int?, end: Int?, contentType: String? ->
var sliceStart: Int = start ?: 0
var sliceEnd: Int = end ?: 0
var sliceEnd: Int = end ?: blob.size
if (sliceStart < 0) {
sliceStart = blob.size + sliceStart
sliceStart = max(blob.size + sliceStart, 0)
} else {
sliceStart = min(sliceStart, blob.size)
}
if (sliceEnd < 0) {
sliceEnd = blob.size + sliceEnd
sliceEnd = max(blob.size + sliceEnd, 0)
} else {
sliceEnd = min(sliceEnd, blob.size)
}
blob.slice(sliceStart, sliceEnd, contentType ?: "")
}
Expand Down
23 changes: 18 additions & 5 deletions packages/expo-blob/build/BlobModule.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-blob/build/BlobModule.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 21 additions & 11 deletions packages/expo-blob/build/BlobModule.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-blob/build/BlobModule.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/expo-blob/build/BlobModule.types.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-blob/build/BlobModule.types.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/expo-blob/build/BlobModule.types.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions packages/expo-blob/build/utils.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/expo-blob/build/utils.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions packages/expo-blob/build/utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/expo-blob/build/utils.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 12 additions & 3 deletions packages/expo-blob/src/BlobModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,21 @@ declare class ExpoBlobModule extends NativeModule {
const NativeBlobModule = requireNativeModule<ExpoBlobModule>("ExpoBlob");

export class ExpoBlob extends NativeBlobModule.Blob implements Blob {
constructor(blobParts?: any[], options?: BlobPropertyBag) {
super(blobParts?.flat(Infinity), options);
constructor(blobParts?: any[] | Iterable<any>, options?: BlobPropertyBag) {
if (options) {
options.type = normalizedContentType(options.type)
}
if (!blobParts) {
super([], options);
} else if (blobParts instanceof Array) {
super(blobParts.flat(Infinity), options);
} else {
super(Array.from(blobParts).flat(Infinity), options);
}
}

slice(start?: number, end?: number, contentType?: string): ExpoBlob {
const normalizedType = contentType ?? normalizedContentType(contentType);
const normalizedType = contentType ? normalizedContentType(contentType) : "";
const slicedBlob = super.slice(start, end, normalizedType);
Object.setPrototypeOf(slicedBlob, ExpoBlob.prototype);
return slicedBlob;
Expand Down