music-metadata 10.6.0 → 10.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/ParserFactory.js +8 -0
- package/lib/apev2/APEv2Parser.d.ts +4 -3
- package/lib/apev2/APEv2Parser.js +5 -3
- package/lib/core.d.ts +3 -3
- package/lib/core.js +6 -8
- package/lib/id3v1/ID3v1Parser.d.ts +3 -3
- package/lib/id3v1/ID3v1Parser.js +5 -3
- package/lib/index.js +2 -9
- package/lib/lyrics3/Lyrics3.d.ts +2 -2
- package/lib/lyrics3/Lyrics3.js +7 -3
- package/lib/mpeg/MpegParser.js +1 -1
- package/lib/type.d.ts +0 -19
- package/package.json +7 -7
- package/lib/common/RandomFileReader.d.ts +0 -21
- package/lib/common/RandomFileReader.js +0 -30
- package/lib/common/RandomUint8ArrayReader.d.ts +0 -18
- package/lib/common/RandomUint8ArrayReader.js +0 -21
package/lib/ParserFactory.js
CHANGED
|
@@ -18,6 +18,7 @@ import { oggParserLoader } from './ogg/OggLoader.js';
|
|
|
18
18
|
import { wavpackParserLoader } from './wavpack/WavPackLoader.js';
|
|
19
19
|
import { riffParserLoader } from './wav/WaveLoader.js';
|
|
20
20
|
import { amrParserLoader } from './amr/AmrLoader.js';
|
|
21
|
+
import { scanAppendingHeaders } from './core.js';
|
|
21
22
|
const debug = initDebug('music-metadata:parser:factory');
|
|
22
23
|
export function parseHttpContentType(contentType) {
|
|
23
24
|
const type = ContentType.parse(contentType);
|
|
@@ -53,6 +54,13 @@ export class ParserFactory {
|
|
|
53
54
|
this.parsers.push(parser);
|
|
54
55
|
}
|
|
55
56
|
async parse(tokenizer, parserLoader, opts) {
|
|
57
|
+
if (tokenizer.supportsRandomAccess()) {
|
|
58
|
+
debug('tokenizer supports random-access, scanning for appending headers');
|
|
59
|
+
await scanAppendingHeaders(tokenizer, opts);
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
debug('tokenizer does not support random-access, cannot scan for appending headers');
|
|
63
|
+
}
|
|
56
64
|
if (!parserLoader) {
|
|
57
65
|
const buf = new Uint8Array(4100);
|
|
58
66
|
if (tokenizer.fileInfo.mimeType) {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as strtok3 from 'strtok3';
|
|
2
|
-
import type { IOptions,
|
|
2
|
+
import type { IOptions, IApeHeader } from '../type.js';
|
|
3
3
|
import type { INativeMetadataCollector } from '../common/MetadataCollector.js';
|
|
4
4
|
import { BasicParser } from '../common/BasicParser.js';
|
|
5
5
|
import { type IFooter, type IHeader } from './APEv2Token.js';
|
|
6
|
+
import type { IRandomAccessTokenizer } from 'strtok3';
|
|
6
7
|
declare const ApeContentError_base: {
|
|
7
8
|
new (message: string): {
|
|
8
9
|
readonly fileType: string;
|
|
@@ -27,10 +28,10 @@ export declare class APEv2Parser extends BasicParser {
|
|
|
27
28
|
static calculateDuration(ah: IHeader): number;
|
|
28
29
|
/**
|
|
29
30
|
* Calculates the APEv1 / APEv2 first field offset
|
|
30
|
-
* @param
|
|
31
|
+
* @param tokenizer
|
|
31
32
|
* @param offset
|
|
32
33
|
*/
|
|
33
|
-
static findApeFooterOffset(
|
|
34
|
+
static findApeFooterOffset(tokenizer: IRandomAccessTokenizer, offset: number): Promise<IApeHeader | undefined>;
|
|
34
35
|
private static parseTagFooter;
|
|
35
36
|
private ape;
|
|
36
37
|
/**
|
package/lib/apev2/APEv2Parser.js
CHANGED
|
@@ -32,13 +32,15 @@ export class APEv2Parser extends BasicParser {
|
|
|
32
32
|
}
|
|
33
33
|
/**
|
|
34
34
|
* Calculates the APEv1 / APEv2 first field offset
|
|
35
|
-
* @param
|
|
35
|
+
* @param tokenizer
|
|
36
36
|
* @param offset
|
|
37
37
|
*/
|
|
38
|
-
static async findApeFooterOffset(
|
|
38
|
+
static async findApeFooterOffset(tokenizer, offset) {
|
|
39
39
|
// Search for APE footer header at the end of the file
|
|
40
40
|
const apeBuf = new Uint8Array(TagFooter.len);
|
|
41
|
-
|
|
41
|
+
const position = tokenizer.position;
|
|
42
|
+
await tokenizer.readBuffer(apeBuf, { position: offset - TagFooter.len });
|
|
43
|
+
tokenizer.setPosition(position);
|
|
42
44
|
const tagFooter = TagFooter.get(apeBuf, 0);
|
|
43
45
|
if (tagFooter.ID === 'APETAGEX') {
|
|
44
46
|
if (tagFooter.flags.isHeader) {
|
package/lib/core.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Primary entry point, Node.js specific entry point is MusepackParser.ts
|
|
3
3
|
*/
|
|
4
|
-
import { type AnyWebByteStream, type IFileInfo, type ITokenizer } from 'strtok3';
|
|
5
|
-
import type { IAudioMetadata, INativeTagDict, IOptions, IPicture, IPrivateOptions,
|
|
4
|
+
import { type AnyWebByteStream, type IFileInfo, type ITokenizer, type IRandomAccessTokenizer } from 'strtok3';
|
|
5
|
+
import type { IAudioMetadata, INativeTagDict, IOptions, IPicture, IPrivateOptions, ITag } from './type.js';
|
|
6
6
|
export type { IFileInfo } from 'strtok3';
|
|
7
7
|
export { type IAudioMetadata, type IOptions, type ITag, type INativeTagDict, type ICommonTagsResult, type IFormat, type IPicture, type IRatio, type IChapter, type ILyricsTag, LyricsContentType, TimestampFormat, IMetadataEventTag, IMetadataEvent } from './type.js';
|
|
8
8
|
export type * from './ParseError.js';
|
|
@@ -56,5 +56,5 @@ export declare function ratingToStars(rating: number | undefined): number;
|
|
|
56
56
|
* @return Cover image, if any, otherwise null
|
|
57
57
|
*/
|
|
58
58
|
export declare function selectCover(pictures?: IPicture[]): IPicture | null;
|
|
59
|
-
export declare function scanAppendingHeaders(
|
|
59
|
+
export declare function scanAppendingHeaders(tokenizer: IRandomAccessTokenizer, options?: IPrivateOptions): Promise<void>;
|
|
60
60
|
export declare function loadMusicMetadata(): Promise<typeof import('music-metadata')>;
|
package/lib/core.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { fromWebStream, fromBuffer } from 'strtok3';
|
|
5
5
|
import { ParserFactory } from './ParserFactory.js';
|
|
6
|
-
import { RandomUint8ArrayReader } from './common/RandomUint8ArrayReader.js';
|
|
7
6
|
import { APEv2Parser } from './apev2/APEv2Parser.js';
|
|
8
7
|
import { hasID3v1Header } from './id3v1/ID3v1Parser.js';
|
|
9
8
|
import { getLyricsHeaderLength } from './lyrics3/Lyrics3.js';
|
|
@@ -41,8 +40,6 @@ export function parseWebStream(webStream, fileInfo, options = {}) {
|
|
|
41
40
|
* Ref: https://github.com/Borewit/strtok3/blob/e6938c81ff685074d5eb3064a11c0b03ca934c1d/src/index.ts#L15
|
|
42
41
|
*/
|
|
43
42
|
export async function parseBuffer(uint8Array, fileInfo, options = {}) {
|
|
44
|
-
const bufferReader = new RandomUint8ArrayReader(uint8Array);
|
|
45
|
-
await scanAppendingHeaders(bufferReader, options);
|
|
46
43
|
const tokenizer = fromBuffer(uint8Array, { fileInfo: typeof fileInfo === 'string' ? { mimeType: fileInfo } : fileInfo });
|
|
47
44
|
return parseFromTokenizer(tokenizer, options);
|
|
48
45
|
}
|
|
@@ -91,12 +88,13 @@ export function selectCover(pictures) {
|
|
|
91
88
|
return acc;
|
|
92
89
|
}) : null;
|
|
93
90
|
}
|
|
94
|
-
export async function scanAppendingHeaders(
|
|
95
|
-
let apeOffset =
|
|
96
|
-
if (await hasID3v1Header(
|
|
91
|
+
export async function scanAppendingHeaders(tokenizer, options = {}) {
|
|
92
|
+
let apeOffset = tokenizer.fileInfo.size;
|
|
93
|
+
if (await hasID3v1Header(tokenizer)) {
|
|
97
94
|
apeOffset -= 128;
|
|
98
|
-
const lyricsLen = await getLyricsHeaderLength(
|
|
95
|
+
const lyricsLen = await getLyricsHeaderLength(tokenizer);
|
|
99
96
|
apeOffset -= lyricsLen;
|
|
100
97
|
}
|
|
101
|
-
options.apeHeader = await APEv2Parser.findApeFooterOffset(
|
|
98
|
+
options.apeHeader = await APEv2Parser.findApeFooterOffset(tokenizer, apeOffset);
|
|
102
99
|
}
|
|
100
|
+
//# sourceMappingURL=core.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ITokenizer } from 'strtok3';
|
|
1
|
+
import type { IRandomAccessTokenizer, ITokenizer } from 'strtok3';
|
|
2
2
|
import { BasicParser } from '../common/BasicParser.js';
|
|
3
|
-
import type { IPrivateOptions
|
|
3
|
+
import type { IPrivateOptions } from '../type.js';
|
|
4
4
|
import type { INativeMetadataCollector } from '../common/MetadataCollector.js';
|
|
5
5
|
/**
|
|
6
6
|
* ID3v1 Genre mappings
|
|
@@ -14,4 +14,4 @@ export declare class ID3v1Parser extends BasicParser {
|
|
|
14
14
|
parse(): Promise<void>;
|
|
15
15
|
private addTag;
|
|
16
16
|
}
|
|
17
|
-
export declare function hasID3v1Header(
|
|
17
|
+
export declare function hasID3v1Header(tokenizer: IRandomAccessTokenizer): Promise<boolean>;
|
package/lib/id3v1/ID3v1Parser.js
CHANGED
|
@@ -124,10 +124,12 @@ export class ID3v1Parser extends BasicParser {
|
|
|
124
124
|
await this.metadata.addTag('ID3v1', id, value);
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
-
export async function hasID3v1Header(
|
|
128
|
-
if (
|
|
127
|
+
export async function hasID3v1Header(tokenizer) {
|
|
128
|
+
if (tokenizer.fileInfo.size >= 128) {
|
|
129
129
|
const tag = new Uint8Array(3);
|
|
130
|
-
|
|
130
|
+
const position = tokenizer.position;
|
|
131
|
+
await tokenizer.readBuffer(tag, { position: tokenizer.fileInfo.size - 128 });
|
|
132
|
+
tokenizer.setPosition(position); // Restore tokenizer position
|
|
131
133
|
return new TextDecoder('latin1').decode(tag) === 'TAG';
|
|
132
134
|
}
|
|
133
135
|
return false;
|
package/lib/index.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { fromFile, fromStream } from 'strtok3';
|
|
5
5
|
import initDebug from 'debug';
|
|
6
|
-
import { parseFromTokenizer,
|
|
6
|
+
import { parseFromTokenizer, } from './core.js';
|
|
7
7
|
import { ParserFactory } from './ParserFactory.js';
|
|
8
|
-
import { RandomFileReader } from './common/RandomFileReader.js';
|
|
9
8
|
export * from './core.js';
|
|
10
9
|
const debug = initDebug('music-metadata:parser');
|
|
11
10
|
/**
|
|
@@ -28,13 +27,6 @@ export async function parseStream(stream, fileInfo, options = {}) {
|
|
|
28
27
|
export async function parseFile(filePath, options = {}) {
|
|
29
28
|
debug(`parseFile: ${filePath}`);
|
|
30
29
|
const fileTokenizer = await fromFile(filePath);
|
|
31
|
-
const fileReader = await RandomFileReader.init(filePath, fileTokenizer.fileInfo.size);
|
|
32
|
-
try {
|
|
33
|
-
await scanAppendingHeaders(fileReader, options);
|
|
34
|
-
}
|
|
35
|
-
finally {
|
|
36
|
-
await fileReader.close();
|
|
37
|
-
}
|
|
38
30
|
const parserFactory = new ParserFactory();
|
|
39
31
|
try {
|
|
40
32
|
const parserLoader = parserFactory.findLoaderForExtension(filePath);
|
|
@@ -46,3 +38,4 @@ export async function parseFile(filePath, options = {}) {
|
|
|
46
38
|
await fileTokenizer.close();
|
|
47
39
|
}
|
|
48
40
|
}
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
package/lib/lyrics3/Lyrics3.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { IRandomAccessTokenizer } from 'strtok3';
|
|
2
2
|
export declare const endTag2 = "LYRICS200";
|
|
3
|
-
export declare function getLyricsHeaderLength(
|
|
3
|
+
export declare function getLyricsHeaderLength(tokenizer: IRandomAccessTokenizer): Promise<number>;
|
package/lib/lyrics3/Lyrics3.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export const endTag2 = 'LYRICS200';
|
|
2
|
-
export async function getLyricsHeaderLength(
|
|
3
|
-
|
|
2
|
+
export async function getLyricsHeaderLength(tokenizer) {
|
|
3
|
+
const fileSize = tokenizer.fileInfo.size;
|
|
4
|
+
if (fileSize >= 143) {
|
|
4
5
|
const buf = new Uint8Array(15);
|
|
5
|
-
|
|
6
|
+
const position = tokenizer.position;
|
|
7
|
+
await tokenizer.readBuffer(buf, { position: fileSize - 143 });
|
|
8
|
+
tokenizer.setPosition(position); // Restore position
|
|
6
9
|
const txt = new TextDecoder('latin1').decode(buf);
|
|
7
10
|
const tag = txt.slice(6);
|
|
8
11
|
if (tag === endTag2) {
|
|
@@ -11,3 +14,4 @@ export async function getLyricsHeaderLength(reader) {
|
|
|
11
14
|
}
|
|
12
15
|
return 0;
|
|
13
16
|
}
|
|
17
|
+
//# sourceMappingURL=Lyrics3.js.map
|
package/lib/mpeg/MpegParser.js
CHANGED
|
@@ -354,7 +354,7 @@ export class MpegParser extends AbstractID3Parser {
|
|
|
354
354
|
if (this.frameCount === 0) {
|
|
355
355
|
this.mpegOffset = this.tokenizer.position - 1;
|
|
356
356
|
}
|
|
357
|
-
await this.tokenizer.peekBuffer(this.buf_frame_header, {
|
|
357
|
+
await this.tokenizer.peekBuffer(this.buf_frame_header.subarray(1), { length: 3 });
|
|
358
358
|
let header;
|
|
359
359
|
try {
|
|
360
360
|
header = FrameHeader.get(this.buf_frame_header, 0);
|
package/lib/type.d.ts
CHANGED
|
@@ -595,25 +595,6 @@ export interface IMetadataEvent {
|
|
|
595
595
|
metadata: IAudioMetadata;
|
|
596
596
|
}
|
|
597
597
|
export type Observer = (update: IMetadataEvent) => void;
|
|
598
|
-
/**
|
|
599
|
-
* Provides random data read access
|
|
600
|
-
* Used read operations on file of buffers
|
|
601
|
-
*/
|
|
602
|
-
export interface IRandomReader {
|
|
603
|
-
/**
|
|
604
|
-
* Total length of file or buffer
|
|
605
|
-
*/
|
|
606
|
-
fileSize: number;
|
|
607
|
-
/**
|
|
608
|
-
* Read from a given position of an abstracted file or buffer.
|
|
609
|
-
* @param {Uint8Array} buffer the buffer that the data will be written to.
|
|
610
|
-
* @param {number} offset the offset in the buffer to start writing at.
|
|
611
|
-
* @param {number} length an integer specifying the number of bytes to read.
|
|
612
|
-
* @param {number} position an argument specifying where to begin reading from in the file.
|
|
613
|
-
* @return {Promise<number>} bytes read
|
|
614
|
-
*/
|
|
615
|
-
randomRead(buffer: Uint8Array, offset: number, length: number, position: number): Promise<number>;
|
|
616
|
-
}
|
|
617
598
|
export interface ILyricsText {
|
|
618
599
|
text: string;
|
|
619
600
|
timestamp?: number;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "music-metadata",
|
|
3
3
|
"description": "Music metadata parser for Node.js, supporting virtual any audio and tag format.",
|
|
4
|
-
"version": "10.6.
|
|
4
|
+
"version": "10.6.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Borewit",
|
|
7
7
|
"url": "https://github.com/Borewit"
|
|
@@ -109,8 +109,9 @@
|
|
|
109
109
|
"content-type": "^1.0.5",
|
|
110
110
|
"debug": "^4.3.7",
|
|
111
111
|
"file-type": "^19.6.0",
|
|
112
|
+
"link": "^2.1.1",
|
|
112
113
|
"media-typer": "^1.1.0",
|
|
113
|
-
"strtok3": "^
|
|
114
|
+
"strtok3": "^10.0.0",
|
|
114
115
|
"token-types": "^6.0.0",
|
|
115
116
|
"uint8array-extras": "^1.4.0"
|
|
116
117
|
},
|
|
@@ -121,19 +122,18 @@
|
|
|
121
122
|
"@types/content-type": "^1.1.8",
|
|
122
123
|
"@types/debug": "^4.1.12",
|
|
123
124
|
"@types/media-typer": "^1.1.3",
|
|
124
|
-
"@types/mocha": "^10.0.
|
|
125
|
-
"@types/node": "^22.
|
|
125
|
+
"@types/mocha": "^10.0.10",
|
|
126
|
+
"@types/node": "^22.10.1",
|
|
126
127
|
"c8": "^10.1.2",
|
|
127
128
|
"chai": "^5.1.2",
|
|
128
|
-
"chai-as-promised": "^8.0.
|
|
129
|
+
"chai-as-promised": "^8.0.1",
|
|
129
130
|
"del-cli": "^6.0.0",
|
|
130
131
|
"mime": "^4.0.4",
|
|
131
132
|
"mocha": "^10.8.2",
|
|
132
|
-
"prettier": "^3.3.3",
|
|
133
133
|
"remark-cli": "^12.0.1",
|
|
134
134
|
"remark-preset-lint-consistent": "^6.0.0",
|
|
135
135
|
"ts-node": "^10.9.2",
|
|
136
|
-
"typescript": "^5.
|
|
136
|
+
"typescript": "^5.7.2"
|
|
137
137
|
},
|
|
138
138
|
"engines": {
|
|
139
139
|
"node": ">=16.0.0"
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { IRandomReader } from '../type.js';
|
|
2
|
-
/**
|
|
3
|
-
* Provides abstract file access via the IRandomRead interface
|
|
4
|
-
*/
|
|
5
|
-
export declare class RandomFileReader implements IRandomReader {
|
|
6
|
-
private readonly fileHandle;
|
|
7
|
-
filePath: string;
|
|
8
|
-
fileSize: number;
|
|
9
|
-
private constructor();
|
|
10
|
-
/**
|
|
11
|
-
* Read from a given position of an abstracted file or buffer.
|
|
12
|
-
* @param buffer {Uint8Array} is the buffer that the data will be written to.
|
|
13
|
-
* @param offset {number} is the offset in the buffer to start writing at.
|
|
14
|
-
* @param length {number}is an integer specifying the number of bytes to read.
|
|
15
|
-
* @param position {number} is an argument specifying where to begin reading from in the file.
|
|
16
|
-
* @return {Promise<number>} bytes read
|
|
17
|
-
*/
|
|
18
|
-
randomRead(buffer: Uint8Array, offset: number, length: number, position: number): Promise<number>;
|
|
19
|
-
close(): Promise<void>;
|
|
20
|
-
static init(filePath: string, fileSize: number): Promise<RandomFileReader>;
|
|
21
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import * as fs from 'node:fs';
|
|
2
|
-
/**
|
|
3
|
-
* Provides abstract file access via the IRandomRead interface
|
|
4
|
-
*/
|
|
5
|
-
export class RandomFileReader {
|
|
6
|
-
constructor(fileHandle, filePath, fileSize) {
|
|
7
|
-
this.fileHandle = fileHandle;
|
|
8
|
-
this.filePath = filePath;
|
|
9
|
-
this.fileSize = fileSize;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Read from a given position of an abstracted file or buffer.
|
|
13
|
-
* @param buffer {Uint8Array} is the buffer that the data will be written to.
|
|
14
|
-
* @param offset {number} is the offset in the buffer to start writing at.
|
|
15
|
-
* @param length {number}is an integer specifying the number of bytes to read.
|
|
16
|
-
* @param position {number} is an argument specifying where to begin reading from in the file.
|
|
17
|
-
* @return {Promise<number>} bytes read
|
|
18
|
-
*/
|
|
19
|
-
async randomRead(buffer, offset, length, position) {
|
|
20
|
-
const result = await this.fileHandle.read(buffer, offset, length, position);
|
|
21
|
-
return result.bytesRead;
|
|
22
|
-
}
|
|
23
|
-
async close() {
|
|
24
|
-
return this.fileHandle.close();
|
|
25
|
-
}
|
|
26
|
-
static async init(filePath, fileSize) {
|
|
27
|
-
const fileHandle = await fs.promises.open(filePath, 'r');
|
|
28
|
-
return new RandomFileReader(fileHandle, filePath, fileSize);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { IRandomReader } from '../type.js';
|
|
2
|
-
/**
|
|
3
|
-
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
4
|
-
*/
|
|
5
|
-
export declare class RandomUint8ArrayReader implements IRandomReader {
|
|
6
|
-
private readonly uint8Array;
|
|
7
|
-
readonly fileSize: number;
|
|
8
|
-
constructor(uint8Array: Uint8Array);
|
|
9
|
-
/**
|
|
10
|
-
* Read from a given position of an abstracted file or buffer.
|
|
11
|
-
* @param uint8Array - Uint8Array that the data will be written to.
|
|
12
|
-
* @param offset - Offset in the buffer to start writing at.
|
|
13
|
-
* @param length - Integer specifying the number of bytes to read.
|
|
14
|
-
* @param position - Specifies where to begin reading from in the file.
|
|
15
|
-
* @return Promise providing bytes read
|
|
16
|
-
*/
|
|
17
|
-
randomRead(uint8Array: Uint8Array, offset: number, length: number, position: number): Promise<number>;
|
|
18
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Provides abstract Uint8Array access via the IRandomRead interface
|
|
3
|
-
*/
|
|
4
|
-
export class RandomUint8ArrayReader {
|
|
5
|
-
constructor(uint8Array) {
|
|
6
|
-
this.uint8Array = uint8Array;
|
|
7
|
-
this.fileSize = uint8Array.length;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Read from a given position of an abstracted file or buffer.
|
|
11
|
-
* @param uint8Array - Uint8Array that the data will be written to.
|
|
12
|
-
* @param offset - Offset in the buffer to start writing at.
|
|
13
|
-
* @param length - Integer specifying the number of bytes to read.
|
|
14
|
-
* @param position - Specifies where to begin reading from in the file.
|
|
15
|
-
* @return Promise providing bytes read
|
|
16
|
-
*/
|
|
17
|
-
async randomRead(uint8Array, offset, length, position) {
|
|
18
|
-
uint8Array.set(this.uint8Array.subarray(position, position + length), offset);
|
|
19
|
-
return length;
|
|
20
|
-
}
|
|
21
|
-
}
|