The file-to-any
is a tiny library that could convert file to arraybuffer, dataUrl and text
npm i file-to-any -S
or
pnpm add file-to-any -S
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
});
The all-purpose api to convert file to others.
- Params
file
Blob | File The file to convert.options
"arrayBuffer" | "dataUrl" | "objectUrl" | "text" | objectoptions.type
"arrayBuffer" | "dataUrl" | "objectUrl" | | "text"options.encoding
"string" | undefined Only used for "text"
- Returns
Promise<any>
Returns the associated result according to the specified parameter.
Convert file to binaryString.
- Params
file
Blob | File The file to convert.- Returns
Promise<string>
Returns a binaryString.
Convert file to arrayBuffer.
- Params
file
Blob | File The file to convert.- Returns
Promise<ArrayBuffer>
Returns a arrayBuffer.
Convert file to dataUrl.
- Params
file
Blob | File The file to convert.- Returns
Promise<string>
Returns a dataUrl.
Convert file to objectUrl.
- Params
file
Blob | File The file to convert.- Returns
Promise<string>
Returns a objectUrl.
Convert file to string.
- Params
file
Blob | File The file to convert.encoding
"string" | undefined Encoding type.- Returns
Promise<string>
Returns a string.