music-metadata 7.11.9 → 7.12.0
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/LICENSE.txt +9 -0
- package/README.md +4 -4
- package/lib/common/RandomFileReader.d.ts +5 -3
- package/lib/common/RandomFileReader.js +12 -15
- package/lib/common/Util.d.ts +1 -2
- package/lib/common/Util.js +7 -7
- package/lib/index.js +2 -2
- package/package.json +10 -10
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2022 Borewit
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -423,12 +423,12 @@ img.src = `data:${picture.format};base64,${picture.data.toString('base64')}`;
|
|
|
423
423
|
|
|
424
424
|
## Licence
|
|
425
425
|
|
|
426
|
-
|
|
426
|
+
The MIT License (MIT)
|
|
427
427
|
|
|
428
|
-
Copyright
|
|
428
|
+
Copyright © 2022 Borewit
|
|
429
429
|
|
|
430
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
|
|
430
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
431
431
|
|
|
432
432
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
433
433
|
|
|
434
|
-
THE SOFTWARE IS PROVIDED
|
|
434
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -4,9 +4,10 @@ import { IRandomReader } from '../type';
|
|
|
4
4
|
* Provides abstract file access via the IRandomRead interface
|
|
5
5
|
*/
|
|
6
6
|
export declare class RandomFileReader implements IRandomReader {
|
|
7
|
+
private readonly fileHandle;
|
|
8
|
+
filePath: string;
|
|
7
9
|
fileSize: number;
|
|
8
|
-
private
|
|
9
|
-
constructor(filePath: string, fileSize: number);
|
|
10
|
+
private constructor();
|
|
10
11
|
/**
|
|
11
12
|
* Read from a given position of an abstracted file or buffer.
|
|
12
13
|
* @param buffer {Buffer} is the buffer that the data will be written to.
|
|
@@ -16,5 +17,6 @@ export declare class RandomFileReader implements IRandomReader {
|
|
|
16
17
|
* @return {Promise<number>} bytes read
|
|
17
18
|
*/
|
|
18
19
|
randomRead(buffer: Buffer, offset: number, length: number, position: number): Promise<number>;
|
|
19
|
-
close(): void
|
|
20
|
+
close(): Promise<void>;
|
|
21
|
+
static init(filePath: string, fileSize: number): Promise<RandomFileReader>;
|
|
20
22
|
}
|
|
@@ -6,9 +6,10 @@ const fs = require("fs");
|
|
|
6
6
|
* Provides abstract file access via the IRandomRead interface
|
|
7
7
|
*/
|
|
8
8
|
class RandomFileReader {
|
|
9
|
-
constructor(filePath, fileSize) {
|
|
9
|
+
constructor(fileHandle, filePath, fileSize) {
|
|
10
|
+
this.fileHandle = fileHandle;
|
|
11
|
+
this.filePath = filePath;
|
|
10
12
|
this.fileSize = fileSize;
|
|
11
|
-
this.fd = fs.openSync(filePath, 'r');
|
|
12
13
|
}
|
|
13
14
|
/**
|
|
14
15
|
* Read from a given position of an abstracted file or buffer.
|
|
@@ -18,20 +19,16 @@ class RandomFileReader {
|
|
|
18
19
|
* @param position {number} is an argument specifying where to begin reading from in the file.
|
|
19
20
|
* @return {Promise<number>} bytes read
|
|
20
21
|
*/
|
|
21
|
-
randomRead(buffer, offset, length, position) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (err) {
|
|
25
|
-
reject(err);
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
resolve(bytesRead);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
22
|
+
async randomRead(buffer, offset, length, position) {
|
|
23
|
+
const result = await this.fileHandle.read(buffer, offset, length, position);
|
|
24
|
+
return result.bytesRead;
|
|
32
25
|
}
|
|
33
|
-
close() {
|
|
34
|
-
|
|
26
|
+
async close() {
|
|
27
|
+
return this.fileHandle.close();
|
|
28
|
+
}
|
|
29
|
+
static async init(filePath, fileSize) {
|
|
30
|
+
const fileHandle = await fs.promises.open(filePath, 'r');
|
|
31
|
+
return new RandomFileReader(fileHandle, filePath, fileSize);
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
exports.RandomFileReader = RandomFileReader;
|
package/lib/common/Util.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
1
|
import { IRatio } from '../type';
|
|
3
2
|
export declare type StringEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
|
|
4
3
|
export interface ITextEncoding {
|
|
@@ -19,7 +18,7 @@ export declare function trimRightNull(x: string): string;
|
|
|
19
18
|
/**
|
|
20
19
|
* Decode string
|
|
21
20
|
*/
|
|
22
|
-
export declare function decodeString(
|
|
21
|
+
export declare function decodeString(uint8Array: Uint8Array, encoding: StringEncoding): string;
|
|
23
22
|
export declare function stripNulls(str: string): string;
|
|
24
23
|
/**
|
|
25
24
|
* Read bit-aligned number start from buffer
|
package/lib/common/Util.js
CHANGED
|
@@ -52,19 +52,19 @@ function swapBytes(uint8Array) {
|
|
|
52
52
|
/**
|
|
53
53
|
* Decode string
|
|
54
54
|
*/
|
|
55
|
-
function decodeString(
|
|
55
|
+
function decodeString(uint8Array, encoding) {
|
|
56
56
|
// annoying workaround for a double BOM issue
|
|
57
57
|
// https://github.com/leetreveil/musicmetadata/issues/84
|
|
58
|
-
if (
|
|
59
|
-
return decodeString(
|
|
58
|
+
if (uint8Array[0] === 0xFF && uint8Array[1] === 0xFE) { // little endian
|
|
59
|
+
return decodeString(uint8Array.subarray(2), encoding);
|
|
60
60
|
}
|
|
61
|
-
else if (encoding === 'utf16le' &&
|
|
61
|
+
else if (encoding === 'utf16le' && uint8Array[0] === 0xFE && uint8Array[1] === 0xFF) {
|
|
62
62
|
// BOM, indicating big endian decoding
|
|
63
|
-
if ((
|
|
63
|
+
if ((uint8Array.length & 1) !== 0)
|
|
64
64
|
throw new Error('Expected even number of octets for 16-bit unicode string');
|
|
65
|
-
return decodeString(swapBytes(
|
|
65
|
+
return decodeString(swapBytes(uint8Array), encoding);
|
|
66
66
|
}
|
|
67
|
-
return
|
|
67
|
+
return Buffer.from(uint8Array).toString(encoding);
|
|
68
68
|
}
|
|
69
69
|
exports.decodeString = decodeString;
|
|
70
70
|
function stripNulls(str) {
|
package/lib/index.js
CHANGED
|
@@ -32,12 +32,12 @@ exports.parseStream = parseStream;
|
|
|
32
32
|
async function parseFile(filePath, options = {}) {
|
|
33
33
|
debug(`parseFile: ${filePath}`);
|
|
34
34
|
const fileTokenizer = await strtok3.fromFile(filePath);
|
|
35
|
-
const fileReader =
|
|
35
|
+
const fileReader = await RandomFileReader_1.RandomFileReader.init(filePath, fileTokenizer.fileInfo.size);
|
|
36
36
|
try {
|
|
37
37
|
await Core.scanAppendingHeaders(fileReader, options);
|
|
38
38
|
}
|
|
39
39
|
finally {
|
|
40
|
-
fileReader.close();
|
|
40
|
+
await fileReader.close();
|
|
41
41
|
}
|
|
42
42
|
try {
|
|
43
43
|
const parserName = ParserFactory_1.ParserFactory.getParserIdForExtension(filePath);
|
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": "7.
|
|
4
|
+
"version": "7.12.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Borewit",
|
|
7
7
|
"url": "https://github.com/Borewit"
|
|
@@ -90,28 +90,28 @@
|
|
|
90
90
|
"file-type": "16.5.3",
|
|
91
91
|
"media-typer": "^1.1.0",
|
|
92
92
|
"strtok3": "^6.2.4",
|
|
93
|
-
"token-types": "^4.
|
|
93
|
+
"token-types": "^4.2.0"
|
|
94
94
|
},
|
|
95
95
|
"devDependencies": {
|
|
96
96
|
"@types/chai": "^4.3.0",
|
|
97
97
|
"@types/debug": "^4.1.7",
|
|
98
98
|
"@types/file-type": "^10.9.1",
|
|
99
99
|
"@types/mocha": "^9.1.0",
|
|
100
|
-
"@types/node": "^17.0.
|
|
101
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
102
|
-
"@typescript-eslint/parser": "^5.
|
|
100
|
+
"@types/node": "^17.0.21",
|
|
101
|
+
"@typescript-eslint/eslint-plugin": "^5.12.1",
|
|
102
|
+
"@typescript-eslint/parser": "^5.12.1",
|
|
103
103
|
"chai": "^4.3.6",
|
|
104
104
|
"coveralls": "^3.1.1",
|
|
105
105
|
"del-cli": "4.0.1",
|
|
106
|
-
"eslint": "^8.
|
|
107
|
-
"eslint-config-prettier": "^8.
|
|
106
|
+
"eslint": "^8.9.0",
|
|
107
|
+
"eslint-config-prettier": "^8.4.0",
|
|
108
108
|
"eslint-import-resolver-typescript": "^2.5.0",
|
|
109
109
|
"eslint-plugin-import": "^2.25.4",
|
|
110
|
-
"eslint-plugin-jsdoc": "^37.
|
|
110
|
+
"eslint-plugin-jsdoc": "^37.9.4",
|
|
111
111
|
"eslint-plugin-node": "^11.1.0",
|
|
112
|
-
"eslint-plugin-unicorn": "^
|
|
112
|
+
"eslint-plugin-unicorn": "^41.0.0",
|
|
113
113
|
"mime": "^3.0.0",
|
|
114
|
-
"mocha": "^9.2.
|
|
114
|
+
"mocha": "^9.2.1",
|
|
115
115
|
"npm-run-all": "^4.1.5",
|
|
116
116
|
"nyc": "^15.1.0",
|
|
117
117
|
"remark-cli": "^10.0.1",
|