file-to-any
The file-to-any
is a tiny library that could convert file to arraybuffer, dataUrl and text
Intall
npm i file-to-any -S
or
pnpm add file-to-any -S
Useage
Here is a simple demo.
import { toAny } from "file-to-any";
// You can get file by input tag with type that is file
toAny(file, "arrayBuffer").then((value) => {
console.log(value); // value is a arrayBuffer
});
API
toAny
The all-purpose api to convert file to others.
- Params
-
file
Blob | File The file to convert. -
options
"arrayBuffer" | "dataUrl" | "text" | object-
options.type
"arrayBuffer" | "dataUrl" | "text" -
options.encoding
"string" | undefined Only used for "text"
-
-
- Returns
-
Promise<any>
Returns the associated result according to the specified parameter.
-
toBinaryString
Convert file to binaryString.
- Params
-
file
Blob | File The file to convert. - Returns
-
Promise<string>
Returns a binaryString.
-
-
toArrayBuffer
Convert file to arrayBuffer.
- Params
-
file
Blob | File The file to convert. - Returns
-
Promise<ArrayBuffer>
Returns a arrayBuffer.
-
-
toDataUrl
Convert file to dataUrl.
- Params
-
file
Blob | File The file to convert. - Returns
-
Promise<string>
Returns a dataUrl.
-
-
toText
Convert file to string.
- Params
-
file
Blob | File The file to convert. -
encoding
"string" | undefined Encoding type. - Returns
-
Promise<string>
Returns a string.
-
-