1.2.0 • Published 2 years ago
file-to-any v1.2.0
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 -Sor
pnpm add file-to-any -SUseage
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
fileBlob | 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.
toBinaryString
Convert file to binaryString.
- Params
fileBlob | File The file to convert.- Returns
Promise<string>Returns a binaryString.
toArrayBuffer
Convert file to arrayBuffer.
- Params
fileBlob | File The file to convert.- Returns
Promise<ArrayBuffer>Returns a arrayBuffer.
toDataUrl
Convert file to dataUrl.
- Params
fileBlob | File The file to convert.- Returns
Promise<string>Returns a dataUrl.
toObjectUrl
Convert file to objectUrl.
- Params
fileBlob | File The file to convert.- Returns
Promise<string>Returns a objectUrl.
toText
Convert file to string.
- Params
fileBlob | File The file to convert.encoding"string" | undefined Encoding type.- Returns
Promise<string>Returns a string.