Convert file to arraybuffer, dataUrl and text
npm install file-to-anyThe file-to-any is a tiny library that could convert file to arraybuffer, dataUrl and text
``shell`
npm i file-to-any -S
or
`shell`
pnpm add file-to-any -S
Here is a simple demo.
`javascript
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"_Promise
- Returns
- Returns the associated result according to the specified parameter.
Convert file to binaryString.
- Params
- file Blob | File The file to convert.Promise
- Returns
- Returns a binaryString.
Convert file to arrayBuffer.
- Params
- file Blob | File The file to convert.Promise
- Returns
- Returns a arrayBuffer.
Convert file to dataUrl.
- Params
- file Blob | File The file to convert.Promise
- Returns
- Returns a dataUrl.
Convert file to objectUrl.
- Params
- file Blob | File The file to convert.Promise
- Returns
- Returns a objectUrl.
Convert file to string.
- Params
- file Blob | File The file to convert.encoding
- "string" | undefined Encoding type.Promise
- Returns
-