music-metadata 7.11.7 → 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.
Files changed (155) hide show
  1. package/LICENSE.txt +9 -0
  2. package/README.md +434 -432
  3. package/lib/ParserFactory.d.ts +48 -49
  4. package/lib/ParserFactory.js +252 -251
  5. package/lib/aiff/AiffParser.d.ts +14 -15
  6. package/lib/aiff/AiffParser.js +84 -85
  7. package/lib/aiff/AiffToken.d.ts +22 -22
  8. package/lib/aiff/AiffToken.js +43 -43
  9. package/lib/apev2/APEv2Parser.d.ts +30 -30
  10. package/lib/apev2/APEv2Parser.js +161 -162
  11. package/lib/apev2/APEv2TagMapper.d.ts +4 -4
  12. package/lib/apev2/APEv2TagMapper.js +86 -86
  13. package/lib/apev2/APEv2Token.d.ts +100 -100
  14. package/lib/apev2/APEv2Token.js +126 -126
  15. package/lib/asf/AsfObject.d.ts +319 -319
  16. package/lib/asf/AsfObject.js +384 -384
  17. package/lib/asf/AsfParser.d.ts +17 -17
  18. package/lib/asf/AsfParser.js +135 -135
  19. package/lib/asf/AsfTagMapper.d.ts +7 -7
  20. package/lib/asf/AsfTagMapper.js +95 -95
  21. package/lib/asf/AsfUtil.d.ts +13 -13
  22. package/lib/asf/AsfUtil.js +40 -40
  23. package/lib/asf/GUID.d.ts +84 -86
  24. package/lib/asf/GUID.js +121 -123
  25. package/lib/common/BasicParser.d.ts +17 -17
  26. package/lib/common/BasicParser.js +18 -18
  27. package/lib/common/CaseInsensitiveTagMap.d.ts +10 -10
  28. package/lib/common/CaseInsensitiveTagMap.js +21 -21
  29. package/lib/common/CombinedTagMapper.d.ts +19 -19
  30. package/lib/common/CombinedTagMapper.js +51 -51
  31. package/lib/common/FourCC.d.ts +6 -6
  32. package/lib/common/FourCC.js +28 -28
  33. package/lib/common/GenericTagMapper.d.ts +51 -51
  34. package/lib/common/GenericTagMapper.js +55 -55
  35. package/lib/common/GenericTagTypes.d.ts +33 -33
  36. package/lib/common/GenericTagTypes.js +131 -131
  37. package/lib/common/MetadataCollector.d.ts +76 -76
  38. package/lib/common/MetadataCollector.js +275 -275
  39. package/lib/common/RandomFileReader.d.ts +22 -20
  40. package/lib/common/RandomFileReader.js +34 -37
  41. package/lib/common/RandomUint8ArrayReader.d.ts +18 -18
  42. package/lib/common/RandomUint8ArrayReader.js +25 -25
  43. package/lib/common/Util.d.ts +57 -58
  44. package/lib/common/Util.js +157 -162
  45. package/lib/core.d.ts +48 -48
  46. package/lib/core.js +90 -90
  47. package/lib/dsdiff/DsdiffParser.d.ts +14 -14
  48. package/lib/dsdiff/DsdiffParser.js +143 -143
  49. package/lib/dsdiff/DsdiffToken.d.ts +9 -9
  50. package/lib/dsdiff/DsdiffToken.js +21 -21
  51. package/lib/dsf/DsfChunk.d.ts +86 -86
  52. package/lib/dsf/DsfChunk.js +54 -54
  53. package/lib/dsf/DsfParser.d.ts +9 -9
  54. package/lib/dsf/DsfParser.js +56 -56
  55. package/lib/flac/FlacParser.d.ts +28 -28
  56. package/lib/flac/FlacParser.js +175 -175
  57. package/lib/id3v1/ID3v1Parser.d.ts +13 -13
  58. package/lib/id3v1/ID3v1Parser.js +134 -134
  59. package/lib/id3v1/ID3v1TagMap.d.ts +4 -4
  60. package/lib/id3v1/ID3v1TagMap.js +22 -22
  61. package/lib/id3v2/AbstractID3Parser.d.ts +17 -17
  62. package/lib/id3v2/AbstractID3Parser.js +60 -60
  63. package/lib/id3v2/FrameParser.d.ts +32 -32
  64. package/lib/id3v2/FrameParser.js +329 -329
  65. package/lib/id3v2/ID3v22TagMapper.d.ts +9 -9
  66. package/lib/id3v2/ID3v22TagMapper.js +55 -55
  67. package/lib/id3v2/ID3v24TagMapper.d.ts +14 -14
  68. package/lib/id3v2/ID3v24TagMapper.js +193 -193
  69. package/lib/id3v2/ID3v2Parser.d.ts +29 -29
  70. package/lib/id3v2/ID3v2Parser.js +184 -194
  71. package/lib/id3v2/ID3v2Token.d.ts +73 -73
  72. package/lib/id3v2/ID3v2Token.js +106 -106
  73. package/lib/iff/index.d.ts +33 -33
  74. package/lib/iff/index.js +19 -19
  75. package/lib/index.d.ts +45 -45
  76. package/lib/index.js +74 -74
  77. package/lib/lyrics3/Lyrics3.d.ts +3 -3
  78. package/lib/lyrics3/Lyrics3.js +17 -17
  79. package/lib/matroska/MatroskaDtd.d.ts +8 -8
  80. package/lib/matroska/MatroskaDtd.js +279 -279
  81. package/lib/matroska/MatroskaParser.d.ts +37 -37
  82. package/lib/matroska/MatroskaParser.js +235 -235
  83. package/lib/matroska/MatroskaTagMapper.d.ts +4 -4
  84. package/lib/matroska/MatroskaTagMapper.js +35 -35
  85. package/lib/matroska/types.d.ts +175 -175
  86. package/lib/matroska/types.js +33 -32
  87. package/lib/mp4/Atom.d.ts +16 -16
  88. package/lib/mp4/Atom.js +70 -70
  89. package/lib/mp4/AtomToken.d.ts +395 -395
  90. package/lib/mp4/AtomToken.js +406 -406
  91. package/lib/mp4/MP4Parser.d.ts +30 -30
  92. package/lib/mp4/MP4Parser.js +511 -511
  93. package/lib/mp4/MP4TagMapper.d.ts +5 -5
  94. package/lib/mp4/MP4TagMapper.js +115 -115
  95. package/lib/mpeg/ExtendedLameHeader.d.ts +27 -27
  96. package/lib/mpeg/ExtendedLameHeader.js +31 -31
  97. package/lib/mpeg/MpegParser.d.ts +49 -49
  98. package/lib/mpeg/MpegParser.js +524 -529
  99. package/lib/mpeg/ReplayGainDataFormat.d.ts +55 -55
  100. package/lib/mpeg/ReplayGainDataFormat.js +69 -69
  101. package/lib/mpeg/XingTag.d.ts +45 -45
  102. package/lib/mpeg/XingTag.js +69 -69
  103. package/lib/musepack/index.d.ts +5 -5
  104. package/lib/musepack/index.js +32 -32
  105. package/lib/musepack/sv7/BitReader.d.ts +13 -13
  106. package/lib/musepack/sv7/BitReader.js +54 -54
  107. package/lib/musepack/sv7/MpcSv7Parser.d.ts +8 -8
  108. package/lib/musepack/sv7/MpcSv7Parser.js +46 -46
  109. package/lib/musepack/sv7/StreamVersion7.d.ts +28 -28
  110. package/lib/musepack/sv7/StreamVersion7.js +41 -41
  111. package/lib/musepack/sv8/MpcSv8Parser.d.ts +6 -6
  112. package/lib/musepack/sv8/MpcSv8Parser.js +55 -55
  113. package/lib/musepack/sv8/StreamVersion8.d.ts +40 -40
  114. package/lib/musepack/sv8/StreamVersion8.js +80 -80
  115. package/lib/ogg/Ogg.d.ts +72 -72
  116. package/lib/ogg/Ogg.js +2 -2
  117. package/lib/ogg/OggParser.d.ts +23 -23
  118. package/lib/ogg/OggParser.js +126 -126
  119. package/lib/ogg/opus/Opus.d.ts +48 -48
  120. package/lib/ogg/opus/Opus.js +28 -28
  121. package/lib/ogg/opus/OpusParser.d.ts +25 -25
  122. package/lib/ogg/opus/OpusParser.js +56 -56
  123. package/lib/ogg/speex/Speex.d.ts +36 -36
  124. package/lib/ogg/speex/Speex.js +31 -31
  125. package/lib/ogg/speex/SpeexParser.d.ts +22 -22
  126. package/lib/ogg/speex/SpeexParser.js +35 -35
  127. package/lib/ogg/theora/Theora.d.ts +20 -20
  128. package/lib/ogg/theora/Theora.js +23 -23
  129. package/lib/ogg/theora/TheoraParser.d.ts +28 -28
  130. package/lib/ogg/theora/TheoraParser.js +44 -44
  131. package/lib/ogg/vorbis/Vorbis.d.ts +69 -79
  132. package/lib/ogg/vorbis/Vorbis.js +78 -78
  133. package/lib/ogg/vorbis/VorbisDecoder.d.ts +12 -12
  134. package/lib/ogg/vorbis/VorbisDecoder.js +32 -32
  135. package/lib/ogg/vorbis/VorbisParser.d.ts +36 -36
  136. package/lib/ogg/vorbis/VorbisParser.js +128 -128
  137. package/lib/ogg/vorbis/VorbisTagMapper.d.ts +7 -7
  138. package/lib/ogg/vorbis/VorbisTagMapper.js +132 -132
  139. package/lib/riff/RiffChunk.d.ts +16 -16
  140. package/lib/riff/RiffChunk.js +32 -32
  141. package/lib/riff/RiffInfoTagMap.d.ts +10 -10
  142. package/lib/riff/RiffInfoTagMap.js +37 -37
  143. package/lib/type.d.ts +592 -599
  144. package/lib/type.js +5 -13
  145. package/lib/wav/BwfChunk.d.ts +17 -0
  146. package/lib/wav/BwfChunk.js +28 -0
  147. package/lib/wav/WaveChunk.d.ts +64 -64
  148. package/lib/wav/WaveChunk.js +65 -65
  149. package/lib/wav/WaveParser.d.ts +24 -24
  150. package/lib/wav/WaveParser.js +156 -144
  151. package/lib/wavpack/WavPackParser.d.ts +14 -14
  152. package/lib/wavpack/WavPackParser.js +99 -105
  153. package/lib/wavpack/WavPackToken.d.ts +64 -64
  154. package/lib/wavpack/WavPackToken.js +76 -76
  155. package/package.json +150 -142
@@ -1,37 +1,34 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RandomFileReader = void 0;
4
- const fs = require("fs");
5
- /**
6
- * Provides abstract file access via the IRandomRead interface
7
- */
8
- class RandomFileReader {
9
- constructor(filePath, fileSize) {
10
- this.fileSize = fileSize;
11
- this.fd = fs.openSync(filePath, 'r');
12
- }
13
- /**
14
- * Read from a given position of an abstracted file or buffer.
15
- * @param buffer {Buffer} is the buffer that the data will be written to.
16
- * @param offset {number} is the offset in the buffer to start writing at.
17
- * @param length {number}is an integer specifying the number of bytes to read.
18
- * @param position {number} is an argument specifying where to begin reading from in the file.
19
- * @return {Promise<number>} bytes read
20
- */
21
- randomRead(buffer, offset, length, position) {
22
- return new Promise((resolve, reject) => {
23
- fs.read(this.fd, buffer, offset, length, position, (err, bytesRead) => {
24
- if (err) {
25
- reject(err);
26
- }
27
- else {
28
- resolve(bytesRead);
29
- }
30
- });
31
- });
32
- }
33
- close() {
34
- fs.closeSync(this.fd);
35
- }
36
- }
37
- exports.RandomFileReader = RandomFileReader;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RandomFileReader = void 0;
4
+ const fs = require("fs");
5
+ /**
6
+ * Provides abstract file access via the IRandomRead interface
7
+ */
8
+ class RandomFileReader {
9
+ constructor(fileHandle, filePath, fileSize) {
10
+ this.fileHandle = fileHandle;
11
+ this.filePath = filePath;
12
+ this.fileSize = fileSize;
13
+ }
14
+ /**
15
+ * Read from a given position of an abstracted file or buffer.
16
+ * @param buffer {Buffer} is the buffer that the data will be written to.
17
+ * @param offset {number} is the offset in the buffer to start writing at.
18
+ * @param length {number}is an integer specifying the number of bytes to read.
19
+ * @param position {number} is an argument specifying where to begin reading from in the file.
20
+ * @return {Promise<number>} bytes read
21
+ */
22
+ async randomRead(buffer, offset, length, position) {
23
+ const result = await this.fileHandle.read(buffer, offset, length, position);
24
+ return result.bytesRead;
25
+ }
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);
32
+ }
33
+ }
34
+ exports.RandomFileReader = RandomFileReader;
@@ -1,18 +1,18 @@
1
- import { IRandomReader } from '../type';
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
+ import { IRandomReader } from '../type';
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,25 +1,25 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RandomUint8ArrayReader = void 0;
4
- /**
5
- * Provides abstract Uint8Array access via the IRandomRead interface
6
- */
7
- class RandomUint8ArrayReader {
8
- constructor(uint8Array) {
9
- this.uint8Array = uint8Array;
10
- this.fileSize = uint8Array.length;
11
- }
12
- /**
13
- * Read from a given position of an abstracted file or buffer.
14
- * @param uint8Array - Uint8Array that the data will be written to.
15
- * @param offset - Offset in the buffer to start writing at.
16
- * @param length - Integer specifying the number of bytes to read.
17
- * @param position - Specifies where to begin reading from in the file.
18
- * @return Promise providing bytes read
19
- */
20
- async randomRead(uint8Array, offset, length, position) {
21
- uint8Array.set(this.uint8Array.subarray(position, position + length), offset);
22
- return length;
23
- }
24
- }
25
- exports.RandomUint8ArrayReader = RandomUint8ArrayReader;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RandomUint8ArrayReader = void 0;
4
+ /**
5
+ * Provides abstract Uint8Array access via the IRandomRead interface
6
+ */
7
+ class RandomUint8ArrayReader {
8
+ constructor(uint8Array) {
9
+ this.uint8Array = uint8Array;
10
+ this.fileSize = uint8Array.length;
11
+ }
12
+ /**
13
+ * Read from a given position of an abstracted file or buffer.
14
+ * @param uint8Array - Uint8Array that the data will be written to.
15
+ * @param offset - Offset in the buffer to start writing at.
16
+ * @param length - Integer specifying the number of bytes to read.
17
+ * @param position - Specifies where to begin reading from in the file.
18
+ * @return Promise providing bytes read
19
+ */
20
+ async randomRead(uint8Array, offset, length, position) {
21
+ uint8Array.set(this.uint8Array.subarray(position, position + length), offset);
22
+ return length;
23
+ }
24
+ }
25
+ exports.RandomUint8ArrayReader = RandomUint8ArrayReader;
@@ -1,58 +1,57 @@
1
- /// <reference types="node" />
2
- import { IRatio } from '../type';
3
- export declare type StringEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
4
- export interface ITextEncoding {
5
- encoding: StringEncoding;
6
- bom?: boolean;
7
- }
8
- export declare function getBit(buf: Uint8Array, off: number, bit: number): boolean;
9
- /**
10
- * Found delimiting zero in uint8Array
11
- * @param uint8Array Uint8Array to find the zero delimiter in
12
- * @param start Offset in uint8Array
13
- * @param end Last position to parse in uint8Array
14
- * @param encoding The string encoding used
15
- * @return Absolute position on uint8Array where zero found
16
- */
17
- export declare function findZero(uint8Array: Uint8Array, start: number, end: number, encoding?: StringEncoding): number;
18
- export declare function trimRightNull(x: string): string;
19
- /**
20
- * Decode string
21
- */
22
- export declare function decodeString(buffer: Buffer, encoding: StringEncoding): string;
23
- export declare function stripNulls(str: string): string;
24
- /**
25
- * Read bit-aligned number start from buffer
26
- * Total offset in bits = byteOffset * 8 + bitOffset
27
- * @param buf Byte buffer
28
- * @param byteOffset Starting offset in bytes
29
- * @param bitOffset Starting offset in bits: 0 = lsb
30
- * @param len Length of number in bits
31
- * @return {number} decoded bit aligned number
32
- */
33
- export declare function getBitAllignedNumber(buf: Uint8Array, byteOffset: number, bitOffset: number, len: number): number;
34
- /**
35
- * Read bit-aligned number start from buffer
36
- * Total offset in bits = byteOffset * 8 + bitOffset
37
- * @param buf Byte buffer
38
- * @param byteOffset Starting offset in bytes
39
- * @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
40
- * @return {number} decoded bit aligned number
41
- */
42
- export declare function isBitSet(buf: Uint8Array, byteOffset: number, bitOffset: number): boolean;
43
- export declare function a2hex(str: string): string;
44
- /**
45
- * Convert power ratio to DB
46
- * ratio: [0..1]
47
- */
48
- export declare function ratioToDb(ratio: number): number;
49
- /**
50
- * Convert dB to ratio
51
- * db Decibels
52
- */
53
- export declare function dbToRatio(dB: number): number;
54
- /**
55
- * Convert replay gain to ratio and Decibel
56
- * @param value string holding a ratio like '0.034' or '-7.54 dB'
57
- */
58
- export declare function toRatio(value: string): IRatio;
1
+ import { IRatio } from '../type';
2
+ export declare type StringEncoding = 'ascii' | 'utf8' | 'utf16le' | 'ucs2' | 'base64url' | 'latin1' | 'hex';
3
+ export interface ITextEncoding {
4
+ encoding: StringEncoding;
5
+ bom?: boolean;
6
+ }
7
+ export declare function getBit(buf: Uint8Array, off: number, bit: number): boolean;
8
+ /**
9
+ * Found delimiting zero in uint8Array
10
+ * @param uint8Array Uint8Array to find the zero delimiter in
11
+ * @param start Offset in uint8Array
12
+ * @param end Last position to parse in uint8Array
13
+ * @param encoding The string encoding used
14
+ * @return Absolute position on uint8Array where zero found
15
+ */
16
+ export declare function findZero(uint8Array: Uint8Array, start: number, end: number, encoding?: StringEncoding): number;
17
+ export declare function trimRightNull(x: string): string;
18
+ /**
19
+ * Decode string
20
+ */
21
+ export declare function decodeString(uint8Array: Uint8Array, encoding: StringEncoding): string;
22
+ export declare function stripNulls(str: string): string;
23
+ /**
24
+ * Read bit-aligned number start from buffer
25
+ * Total offset in bits = byteOffset * 8 + bitOffset
26
+ * @param buf Byte buffer
27
+ * @param byteOffset Starting offset in bytes
28
+ * @param bitOffset Starting offset in bits: 0 = lsb
29
+ * @param len Length of number in bits
30
+ * @return {number} decoded bit aligned number
31
+ */
32
+ export declare function getBitAllignedNumber(buf: Uint8Array, byteOffset: number, bitOffset: number, len: number): number;
33
+ /**
34
+ * Read bit-aligned number start from buffer
35
+ * Total offset in bits = byteOffset * 8 + bitOffset
36
+ * @param buf Byte buffer
37
+ * @param byteOffset Starting offset in bytes
38
+ * @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
39
+ * @return {number} decoded bit aligned number
40
+ */
41
+ export declare function isBitSet(buf: Uint8Array, byteOffset: number, bitOffset: number): boolean;
42
+ export declare function a2hex(str: string): string;
43
+ /**
44
+ * Convert power ratio to DB
45
+ * ratio: [0..1]
46
+ */
47
+ export declare function ratioToDb(ratio: number): number;
48
+ /**
49
+ * Convert dB to ratio
50
+ * db Decibels
51
+ */
52
+ export declare function dbToRatio(dB: number): number;
53
+ /**
54
+ * Convert replay gain to ratio and Decibel
55
+ * @param value string holding a ratio like '0.034' or '-7.54 dB'
56
+ */
57
+ export declare function toRatio(value: string): IRatio;
@@ -1,163 +1,158 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toRatio = exports.dbToRatio = exports.ratioToDb = exports.a2hex = exports.isBitSet = exports.getBitAllignedNumber = exports.stripNulls = exports.decodeString = exports.trimRightNull = exports.findZero = exports.getBit = void 0;
4
- function getBit(buf, off, bit) {
5
- return (buf[off] & (1 << bit)) !== 0;
6
- }
7
- exports.getBit = getBit;
8
- /**
9
- * Found delimiting zero in uint8Array
10
- * @param uint8Array Uint8Array to find the zero delimiter in
11
- * @param start Offset in uint8Array
12
- * @param end Last position to parse in uint8Array
13
- * @param encoding The string encoding used
14
- * @return Absolute position on uint8Array where zero found
15
- */
16
- function findZero(uint8Array, start, end, encoding) {
17
- let i = start;
18
- if (encoding === 'utf16le') {
19
- while (uint8Array[i] !== 0 || uint8Array[i + 1] !== 0) {
20
- if (i >= end)
21
- return end;
22
- i += 2;
23
- }
24
- return i;
25
- }
26
- else {
27
- while (uint8Array[i] !== 0) {
28
- if (i >= end)
29
- return end;
30
- i++;
31
- }
32
- return i;
33
- }
34
- }
35
- exports.findZero = findZero;
36
- function trimRightNull(x) {
37
- const pos0 = x.indexOf('\0');
38
- return pos0 === -1 ? x : x.substr(0, pos0);
39
- }
40
- exports.trimRightNull = trimRightNull;
41
- function swapBytes(uint8Array) {
42
- const l = uint8Array.length;
43
- if ((l & 1) !== 0)
44
- throw new Error('Buffer length must be even');
45
- for (let i = 0; i < l; i += 2) {
46
- const a = uint8Array[i];
47
- uint8Array[i] = uint8Array[i + 1];
48
- uint8Array[i + 1] = a;
49
- }
50
- return uint8Array;
51
- }
52
- /**
53
- * Decode string
54
- */
55
- function decodeString(buffer, encoding) {
56
- // annoying workaround for a double BOM issue
57
- // https://github.com/leetreveil/musicmetadata/issues/84
58
- if (buffer[0] === 0xFF && buffer[1] === 0xFE) { // little endian
59
- return decodeString(buffer.subarray(2), encoding);
60
- }
61
- else if (encoding === 'utf16le' && buffer[0] === 0xFE && buffer[1] === 0xFF) {
62
- // BOM, indicating big endian decoding
63
- if ((buffer.length & 1) !== 0)
64
- throw new Error('Expected even number of octets for 16-bit unicode string');
65
- return decodeString(swapBytes(buffer), encoding);
66
- }
67
- return buffer.toString(encoding);
68
- }
69
- exports.decodeString = decodeString;
70
- function stripNulls(str) {
71
- str = str.replace(/^\x00+/g, '');
72
- str = str.replace(/\x00+$/g, '');
73
- return str;
74
- }
75
- exports.stripNulls = stripNulls;
76
- /**
77
- * Read bit-aligned number start from buffer
78
- * Total offset in bits = byteOffset * 8 + bitOffset
79
- * @param buf Byte buffer
80
- * @param byteOffset Starting offset in bytes
81
- * @param bitOffset Starting offset in bits: 0 = lsb
82
- * @param len Length of number in bits
83
- * @return {number} decoded bit aligned number
84
- */
85
- function getBitAllignedNumber(buf, byteOffset, bitOffset, len) {
86
- const byteOff = byteOffset + ~~(bitOffset / 8);
87
- const bitOff = bitOffset % 8;
88
- let value = buf[byteOff];
89
- value &= 0xff >> bitOff;
90
- const bitsRead = 8 - bitOff;
91
- const bitsLeft = len - bitsRead;
92
- if (bitsLeft < 0) {
93
- value >>= (8 - bitOff - len);
94
- }
95
- else if (bitsLeft > 0) {
96
- value <<= bitsLeft;
97
- value |= getBitAllignedNumber(buf, byteOffset, bitOffset + bitsRead, bitsLeft);
98
- }
99
- return value;
100
- }
101
- exports.getBitAllignedNumber = getBitAllignedNumber;
102
- /**
103
- * Read bit-aligned number start from buffer
104
- * Total offset in bits = byteOffset * 8 + bitOffset
105
- * @param buf Byte buffer
106
- * @param byteOffset Starting offset in bytes
107
- * @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
108
- * @return {number} decoded bit aligned number
109
- */
110
- function isBitSet(buf, byteOffset, bitOffset) {
111
- return getBitAllignedNumber(buf, byteOffset, bitOffset, 1) === 1;
112
- }
113
- exports.isBitSet = isBitSet;
114
- function a2hex(str) {
115
- const arr = [];
116
- for (let i = 0, l = str.length; i < l; i++) {
117
- const hex = Number(str.charCodeAt(i)).toString(16);
118
- arr.push(hex.length === 1 ? '0' + hex : hex);
119
- }
120
- return arr.join(' ');
121
- }
122
- exports.a2hex = a2hex;
123
- /**
124
- * Convert power ratio to DB
125
- * ratio: [0..1]
126
- */
127
- function ratioToDb(ratio) {
128
- return 10 * Math.log10(ratio);
129
- }
130
- exports.ratioToDb = ratioToDb;
131
- /**
132
- * Convert dB to ratio
133
- * db Decibels
134
- */
135
- function dbToRatio(dB) {
136
- return Math.pow(10, dB / 10);
137
- }
138
- exports.dbToRatio = dbToRatio;
139
- /**
140
- * Convert replay gain to ratio and Decibel
141
- * @param value string holding a ratio like '0.034' or '-7.54 dB'
142
- */
143
- function toRatio(value) {
144
- const ps = value.split(' ').map(p => p.trim().toLowerCase());
145
- // @ts-ignore
146
- if (ps.length >= 1) {
147
- const v = parseFloat(ps[0]);
148
- if (ps.length === 2 && ps[1] === 'db') {
149
- return {
150
- dB: v,
151
- ratio: dbToRatio(v)
152
- };
153
- }
154
- else {
155
- return {
156
- dB: ratioToDb(v),
157
- ratio: v
158
- };
159
- }
160
- }
161
- }
162
- exports.toRatio = toRatio;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toRatio = exports.dbToRatio = exports.ratioToDb = exports.a2hex = exports.isBitSet = exports.getBitAllignedNumber = exports.stripNulls = exports.decodeString = exports.trimRightNull = exports.findZero = exports.getBit = void 0;
4
+ function getBit(buf, off, bit) {
5
+ return (buf[off] & (1 << bit)) !== 0;
6
+ }
7
+ exports.getBit = getBit;
8
+ /**
9
+ * Found delimiting zero in uint8Array
10
+ * @param uint8Array Uint8Array to find the zero delimiter in
11
+ * @param start Offset in uint8Array
12
+ * @param end Last position to parse in uint8Array
13
+ * @param encoding The string encoding used
14
+ * @return Absolute position on uint8Array where zero found
15
+ */
16
+ function findZero(uint8Array, start, end, encoding) {
17
+ let i = start;
18
+ if (encoding === 'utf16le') {
19
+ while (uint8Array[i] !== 0 || uint8Array[i + 1] !== 0) {
20
+ if (i >= end)
21
+ return end;
22
+ i += 2;
23
+ }
24
+ return i;
25
+ }
26
+ else {
27
+ while (uint8Array[i] !== 0) {
28
+ if (i >= end)
29
+ return end;
30
+ i++;
31
+ }
32
+ return i;
33
+ }
34
+ }
35
+ exports.findZero = findZero;
36
+ function trimRightNull(x) {
37
+ const pos0 = x.indexOf('\0');
38
+ return pos0 === -1 ? x : x.substr(0, pos0);
39
+ }
40
+ exports.trimRightNull = trimRightNull;
41
+ function swapBytes(uint8Array) {
42
+ const l = uint8Array.length;
43
+ if ((l & 1) !== 0)
44
+ throw new Error('Buffer length must be even');
45
+ for (let i = 0; i < l; i += 2) {
46
+ const a = uint8Array[i];
47
+ uint8Array[i] = uint8Array[i + 1];
48
+ uint8Array[i + 1] = a;
49
+ }
50
+ return uint8Array;
51
+ }
52
+ /**
53
+ * Decode string
54
+ */
55
+ function decodeString(uint8Array, encoding) {
56
+ // annoying workaround for a double BOM issue
57
+ // https://github.com/leetreveil/musicmetadata/issues/84
58
+ if (uint8Array[0] === 0xFF && uint8Array[1] === 0xFE) { // little endian
59
+ return decodeString(uint8Array.subarray(2), encoding);
60
+ }
61
+ else if (encoding === 'utf16le' && uint8Array[0] === 0xFE && uint8Array[1] === 0xFF) {
62
+ // BOM, indicating big endian decoding
63
+ if ((uint8Array.length & 1) !== 0)
64
+ throw new Error('Expected even number of octets for 16-bit unicode string');
65
+ return decodeString(swapBytes(uint8Array), encoding);
66
+ }
67
+ return Buffer.from(uint8Array).toString(encoding);
68
+ }
69
+ exports.decodeString = decodeString;
70
+ function stripNulls(str) {
71
+ str = str.replace(/^\x00+/g, '');
72
+ str = str.replace(/\x00+$/g, '');
73
+ return str;
74
+ }
75
+ exports.stripNulls = stripNulls;
76
+ /**
77
+ * Read bit-aligned number start from buffer
78
+ * Total offset in bits = byteOffset * 8 + bitOffset
79
+ * @param buf Byte buffer
80
+ * @param byteOffset Starting offset in bytes
81
+ * @param bitOffset Starting offset in bits: 0 = lsb
82
+ * @param len Length of number in bits
83
+ * @return {number} decoded bit aligned number
84
+ */
85
+ function getBitAllignedNumber(buf, byteOffset, bitOffset, len) {
86
+ const byteOff = byteOffset + ~~(bitOffset / 8);
87
+ const bitOff = bitOffset % 8;
88
+ let value = buf[byteOff];
89
+ value &= 0xff >> bitOff;
90
+ const bitsRead = 8 - bitOff;
91
+ const bitsLeft = len - bitsRead;
92
+ if (bitsLeft < 0) {
93
+ value >>= (8 - bitOff - len);
94
+ }
95
+ else if (bitsLeft > 0) {
96
+ value <<= bitsLeft;
97
+ value |= getBitAllignedNumber(buf, byteOffset, bitOffset + bitsRead, bitsLeft);
98
+ }
99
+ return value;
100
+ }
101
+ exports.getBitAllignedNumber = getBitAllignedNumber;
102
+ /**
103
+ * Read bit-aligned number start from buffer
104
+ * Total offset in bits = byteOffset * 8 + bitOffset
105
+ * @param buf Byte buffer
106
+ * @param byteOffset Starting offset in bytes
107
+ * @param bitOffset Starting offset in bits: 0 = most significant bit, 7 is least significant bit
108
+ * @return {number} decoded bit aligned number
109
+ */
110
+ function isBitSet(buf, byteOffset, bitOffset) {
111
+ return getBitAllignedNumber(buf, byteOffset, bitOffset, 1) === 1;
112
+ }
113
+ exports.isBitSet = isBitSet;
114
+ function a2hex(str) {
115
+ const arr = [];
116
+ for (let i = 0, l = str.length; i < l; i++) {
117
+ const hex = Number(str.charCodeAt(i)).toString(16);
118
+ arr.push(hex.length === 1 ? '0' + hex : hex);
119
+ }
120
+ return arr.join(' ');
121
+ }
122
+ exports.a2hex = a2hex;
123
+ /**
124
+ * Convert power ratio to DB
125
+ * ratio: [0..1]
126
+ */
127
+ function ratioToDb(ratio) {
128
+ return 10 * Math.log10(ratio);
129
+ }
130
+ exports.ratioToDb = ratioToDb;
131
+ /**
132
+ * Convert dB to ratio
133
+ * db Decibels
134
+ */
135
+ function dbToRatio(dB) {
136
+ return Math.pow(10, dB / 10);
137
+ }
138
+ exports.dbToRatio = dbToRatio;
139
+ /**
140
+ * Convert replay gain to ratio and Decibel
141
+ * @param value string holding a ratio like '0.034' or '-7.54 dB'
142
+ */
143
+ function toRatio(value) {
144
+ const ps = value.split(' ').map(p => p.trim().toLowerCase());
145
+ // @ts-ignore
146
+ if (ps.length >= 1) {
147
+ const v = parseFloat(ps[0]);
148
+ return ps.length === 2 && ps[1] === 'db' ? {
149
+ dB: v,
150
+ ratio: dbToRatio(v)
151
+ } : {
152
+ dB: ratioToDb(v),
153
+ ratio: v
154
+ };
155
+ }
156
+ }
157
+ exports.toRatio = toRatio;
163
158
  //# sourceMappingURL=Util.js.map