forked from Borewit/music-metadata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mikiymk/include-packages
Include packages
- Loading branch information
Showing
307 changed files
with
19,825 additions
and
299 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
test/samples/ | ||
test/peek-readable/resources/ | ||
test/strtok3/resources/ | ||
test/file-type/fixture/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* Read-only token | ||
* See https://github.com/Borewit/strtok3 for more information | ||
*/ | ||
export interface IGetToken<V, VS extends Uint8Array = Uint8Array> { | ||
/** | ||
* Length of encoded token in bytes | ||
*/ | ||
len: number; | ||
|
||
/** | ||
* Decode value from buffer at offset | ||
* @param array - Uint8Array to read the decoded value from | ||
* @param offset - Decode offset | ||
* @return decoded value | ||
*/ | ||
get(array: VS, offset: number): V; | ||
} | ||
|
||
export interface IToken<V, VS extends Uint8Array = Uint8Array> | ||
extends IGetToken<V, VS> { | ||
/** | ||
* Encode value to buffer | ||
* @param array - Uint8Array to write the encoded value to | ||
* @param offset - Buffer write offset | ||
* @param value - Value to decode of type T | ||
* @return offset plus number of bytes written | ||
*/ | ||
put(array: VS, offset: number, value: V): number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { Buffer } from "node:buffer"; | ||
import { fileTypeFromBuffer, FileTypeResult } from "./core"; | ||
|
||
/** | ||
* Convert Blobs to ArrayBuffer. | ||
* @param blob - Web API Blob. | ||
* @returns | ||
*/ | ||
function blobToArrayBuffer(blob: Blob): Promise<ArrayBuffer> { | ||
if (blob.arrayBuffer) { | ||
return blob.arrayBuffer(); | ||
} | ||
|
||
// TODO: Remove when stop supporting older environments | ||
return new Promise((resolve, reject) => { | ||
const fileReader = new FileReader(); | ||
fileReader.addEventListener("loadend", (event) => { | ||
resolve(event.target.result as ArrayBuffer); | ||
}); | ||
|
||
fileReader.addEventListener("error", (event) => { | ||
reject(new Error(event.toString())); | ||
}); | ||
|
||
fileReader.addEventListener("abort", (event) => { | ||
reject(new Error(event.type)); | ||
}); | ||
|
||
fileReader.readAsArrayBuffer(blob); | ||
}); | ||
} | ||
|
||
/** | ||
* Detect the file type of a [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob). | ||
* | ||
* __Note:__ This method is only available in the browser. | ||
* @example | ||
* ``` | ||
* import {fileTypeFromBlob} from 'file-type'; | ||
* | ||
* const blob = new Blob(['<?xml version="1.0" encoding="ISO-8859-1" ?>'], { | ||
* type: 'plain/text', | ||
* endings: 'native' | ||
* }); | ||
* | ||
* console.log(await fileTypeFromBlob(blob)); | ||
* //=> {ext: 'txt', mime: 'plain/text'} | ||
* ``` | ||
*/ | ||
export async function fileTypeFromBlob( | ||
blob: Blob | ||
): Promise<FileTypeResult | undefined> { | ||
const buffer = await blobToArrayBuffer(blob); | ||
return fileTypeFromBuffer(Buffer.from(buffer)); | ||
} | ||
|
||
export { | ||
fileTypeFromTokenizer, | ||
fileTypeFromBuffer, | ||
fileTypeStream, | ||
} from "./core"; | ||
export { | ||
supportedExtensions, | ||
supportedMimeTypes, | ||
FileTypeResult, | ||
FileExtension, | ||
MimeType, | ||
} from "./core"; |
Oops, something went wrong.