Skip to content

Commit

Permalink
remove blob convert.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Feb 6, 2024
1 parent 5ba0898 commit 0f5f991
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 41 deletions.
29 changes: 0 additions & 29 deletions src/pure/byte.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
import {b64Encode} from "./base64.ts";

interface BlobType{
"text": string;
"base64": string;
"byte": Uint8Array;
"buffer": ArrayBuffer;
"stream": ReadableStream<Uint8Array>;
}

/**
* Convert from blob to specified data type.
* @example
* ```ts
* const blob = new Blob(["my-text"]);
* const data = await blobConvert(blob, "text");
* ```
*/
export async function blobConvert<T extends keyof BlobType>(blob:Blob, type:T):Promise<BlobType[T]>{
switch(type){
case "text": return <BlobType[T]>await blob.text();
case "base64": return <BlobType[T]>b64Encode(new Uint8Array(await blob.arrayBuffer()));
case "byte": return <BlobType[T]>new Uint8Array(await blob.arrayBuffer());
case "buffer": return <BlobType[T]>await blob.arrayBuffer();
case "stream": return <BlobType[T]>blob.stream();
default: throw new Error();
}
}

/**
* Concat multiple buffer sources into single binary.
* @example
Expand Down
13 changes: 1 addition & 12 deletions test/pure/byte.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,5 @@
import {assertEquals} from "../../deps.test.ts";
import {blobConvert, byteConcat} from "../../src/pure/byte.ts";

const sample = "hello!";

Deno.test({
name: "Byte: Blob Convert",
async fn(){
const data = await blobConvert(new Blob([sample]), "text");

assertEquals(data, sample);
}
});
import {byteConcat} from "../../src/pure/byte.ts";

Deno.test({
name: "Byte: Concat",
Expand Down

0 comments on commit 0f5f991

Please sign in to comment.