aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/bun-types/globals.d.ts24
-rw-r--r--test/js/web/fetch/blob.test.ts14
2 files changed, 37 insertions, 1 deletions
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts
index 2dd86f911..aab4921bd 100644
--- a/packages/bun-types/globals.d.ts
+++ b/packages/bun-types/globals.d.ts
@@ -565,7 +565,29 @@ declare class Blob implements BlobInterface {
* @param end The index that sets the end of the view.
*
*/
- slice(begin?: number, end?: number): Blob;
+ slice(begin?: number, end?: number, contentType?: string): Blob;
+
+ /**
+ * Create a new view **without 🚫 copying** the underlying data.
+ *
+ * Similar to [`BufferSource.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BufferSource/subarray)
+ *
+ * @param begin The index that sets the beginning of the view.
+ * @param end The index that sets the end of the view.
+ *
+ */
+ slice(begin?: number, contentType?: string): Blob;
+
+ /**
+ * Create a new view **without 🚫 copying** the underlying data.
+ *
+ * Similar to [`BufferSource.subarray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BufferSource/subarray)
+ *
+ * @param begin The index that sets the beginning of the view.
+ * @param end The index that sets the end of the view.
+ *
+ */
+ slice(contentType?: string): Blob;
/**
* Read the data from the blob as a string. It will be decoded from UTF-8.
diff --git a/test/js/web/fetch/blob.test.ts b/test/js/web/fetch/blob.test.ts
index b5a256671..ba44f8c1b 100644
--- a/test/js/web/fetch/blob.test.ts
+++ b/test/js/web/fetch/blob.test.ts
@@ -12,6 +12,20 @@ test("Blob.slice", () => {
expect(b3.size).toBe(0);
const b4 = blob.slice(0, 10);
expect(b4.size).toBe(blob.size);
+
+ expect(blob.slice().size).toBe(blob.size);
+ expect(blob.slice(0).size).toBe(blob.size);
+ expect(blob.slice(NaN).size).toBe(blob.size);
+ expect(blob.slice(0, Infinity).size).toBe(blob.size);
+ expect(blob.slice(-Infinity).size).toBe(blob.size);
+ expect(blob.slice(0, NaN).size).toBe(0);
+ // @ts-expect-error
+ expect(blob.slice(Symbol(), "-123").size).toBe(6);
+ expect(blob.slice(Object.create(null), "-123").size).toBe(6);
+ // @ts-expect-error
+ expect(blob.slice(null, "-123").size).toBe(6);
+ expect(blob.slice(0, 10).size).toBe(blob.size);
+ expect(blob.slice("text/plain;charset=utf-8").type).toBe("text/plain;charset=utf-8");
});
test("new Blob", () => {