music-metadata 7.11.3 → 7.11.7

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