metadata-detector-worker 4.0.38

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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +6 -0
  3. package/build/es2019/helpers/concat.d.ts +2 -0
  4. package/build/es2019/helpers/concat.d.ts.map +1 -0
  5. package/build/es2019/helpers/concat.js +10 -0
  6. package/build/es2019/helpers/concat.js.map +1 -0
  7. package/build/es2019/helpers/decode.d.ts +2 -0
  8. package/build/es2019/helpers/decode.d.ts.map +1 -0
  9. package/build/es2019/helpers/decode.js +13 -0
  10. package/build/es2019/helpers/decode.js.map +1 -0
  11. package/build/es2019/helpers/locate.d.ts +2 -0
  12. package/build/es2019/helpers/locate.d.ts.map +1 -0
  13. package/build/es2019/helpers/locate.js +72 -0
  14. package/build/es2019/helpers/locate.js.map +1 -0
  15. package/build/es2019/helpers/strip.d.ts +2 -0
  16. package/build/es2019/helpers/strip.d.ts.map +1 -0
  17. package/build/es2019/helpers/strip.js +21 -0
  18. package/build/es2019/helpers/strip.js.map +1 -0
  19. package/build/es2019/interfaces/broker-event.d.ts +5 -0
  20. package/build/es2019/interfaces/broker-event.d.ts.map +1 -0
  21. package/build/es2019/interfaces/broker-event.js +2 -0
  22. package/build/es2019/interfaces/broker-event.js.map +1 -0
  23. package/build/es2019/interfaces/error-response.d.ts +8 -0
  24. package/build/es2019/interfaces/error-response.d.ts.map +1 -0
  25. package/build/es2019/interfaces/error-response.js +2 -0
  26. package/build/es2019/interfaces/error-response.js.map +1 -0
  27. package/build/es2019/interfaces/index.d.ts +8 -0
  28. package/build/es2019/interfaces/index.d.ts.map +1 -0
  29. package/build/es2019/interfaces/index.js +8 -0
  30. package/build/es2019/interfaces/index.js.map +1 -0
  31. package/build/es2019/interfaces/locate-request.d.ts +8 -0
  32. package/build/es2019/interfaces/locate-request.d.ts.map +1 -0
  33. package/build/es2019/interfaces/locate-request.js +2 -0
  34. package/build/es2019/interfaces/locate-request.js.map +1 -0
  35. package/build/es2019/interfaces/locate-response.d.ts +8 -0
  36. package/build/es2019/interfaces/locate-response.d.ts.map +1 -0
  37. package/build/es2019/interfaces/locate-response.js +2 -0
  38. package/build/es2019/interfaces/locate-response.js.map +1 -0
  39. package/build/es2019/interfaces/strip-request.d.ts +8 -0
  40. package/build/es2019/interfaces/strip-request.d.ts.map +1 -0
  41. package/build/es2019/interfaces/strip-request.js +2 -0
  42. package/build/es2019/interfaces/strip-request.js.map +1 -0
  43. package/build/es2019/interfaces/strip-response.d.ts +8 -0
  44. package/build/es2019/interfaces/strip-response.d.ts.map +1 -0
  45. package/build/es2019/interfaces/strip-response.js +2 -0
  46. package/build/es2019/interfaces/strip-response.js.map +1 -0
  47. package/build/es2019/interfaces/worker-event.d.ts +5 -0
  48. package/build/es2019/interfaces/worker-event.d.ts.map +1 -0
  49. package/build/es2019/interfaces/worker-event.js +2 -0
  50. package/build/es2019/interfaces/worker-event.js.map +1 -0
  51. package/build/es2019/module.d.ts +3 -0
  52. package/build/es2019/module.d.ts.map +1 -0
  53. package/build/es2019/module.js +40 -0
  54. package/build/es2019/module.js.map +1 -0
  55. package/build/es2019/types/broker-message.d.ts +3 -0
  56. package/build/es2019/types/broker-message.d.ts.map +1 -0
  57. package/build/es2019/types/broker-message.js +2 -0
  58. package/build/es2019/types/broker-message.js.map +1 -0
  59. package/build/es2019/types/index.d.ts +3 -0
  60. package/build/es2019/types/index.d.ts.map +1 -0
  61. package/build/es2019/types/index.js +3 -0
  62. package/build/es2019/types/index.js.map +1 -0
  63. package/build/es2019/types/worker-message.d.ts +3 -0
  64. package/build/es2019/types/worker-message.d.ts.map +1 -0
  65. package/build/es2019/types/worker-message.js +2 -0
  66. package/build/es2019/types/worker-message.js.map +1 -0
  67. package/build/es5/bundle.js +202 -0
  68. package/package.json +82 -0
  69. package/src/helpers/concat.ts +13 -0
  70. package/src/helpers/decode.ts +15 -0
  71. package/src/helpers/locate.ts +106 -0
  72. package/src/helpers/strip.ts +26 -0
  73. package/src/interfaces/broker-event.ts +5 -0
  74. package/src/interfaces/error-response.ts +9 -0
  75. package/src/interfaces/index.ts +7 -0
  76. package/src/interfaces/locate-request.ts +9 -0
  77. package/src/interfaces/locate-response.ts +9 -0
  78. package/src/interfaces/strip-request.ts +9 -0
  79. package/src/interfaces/strip-response.ts +9 -0
  80. package/src/interfaces/worker-event.ts +5 -0
  81. package/src/module.ts +53 -0
  82. package/src/tsconfig.json +6 -0
  83. package/src/types/broker-message.ts +3 -0
  84. package/src/types/index.ts +2 -0
  85. package/src/types/worker-message.ts +3 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Christoph Guttandin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,6 @@
1
+ # metadata-detector-worker
2
+
3
+ **The worker which is used by the metadata-detector package.**
4
+
5
+ [![dependencies](https://img.shields.io/david/chrisguttandin/metadata-detector-worker.svg?style=flat-square)](https://github.com/chrisguttandin/metadata-detector-worker/network/dependencies)
6
+ [![version](https://img.shields.io/npm/v/metadata-detector-worker.svg?style=flat-square)](https://www.npmjs.com/package/metadata-detector-worker)
@@ -0,0 +1,2 @@
1
+ export declare const concat: (...arrayBuffers: ArrayBuffer[]) => ArrayBuffer;
2
+ //# sourceMappingURL=concat.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat.d.ts","sourceRoot":"","sources":["../../../src/helpers/concat.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,MAAM,oBAAqB,WAAW,EAAE,gBAYpD,CAAC"}
@@ -0,0 +1,10 @@
1
+ export const concat = (...arrayBuffers) => {
2
+ return arrayBuffers.reduce(({ array, offset }, arrayBuffer) => {
3
+ array.set(new Uint8Array(arrayBuffer), offset);
4
+ return { array, offset: offset + arrayBuffer.byteLength };
5
+ }, {
6
+ array: new Uint8Array(arrayBuffers.reduce((byteLength, arrayBuffer) => byteLength + arrayBuffer.byteLength, 0)),
7
+ offset: 0
8
+ }).array.buffer;
9
+ };
10
+ //# sourceMappingURL=concat.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"concat.js","sourceRoot":"","sources":["../../../src/helpers/concat.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,GAAG,YAA2B,EAAE,EAAE;IACrD,OAAoB,YAAY,CAAC,MAAM,CACnC,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,WAAW,EAAE,EAAE;QAC/B,KAAK,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAAC;QAE/C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC;IAC9D,CAAC,EACD;QACI,KAAK,EAAE,IAAI,UAAU,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,WAAW,EAAE,EAAE,CAAC,UAAU,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;QAC/G,MAAM,EAAE,CAAC;KACZ,CACJ,CAAC,KAAK,CAAC,MAAM,CAAC;AACnB,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const decode: (dataView: DataView) => string;
2
+ //# sourceMappingURL=decode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../../../src/helpers/decode.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,aAAc,QAAQ,WAYxC,CAAC"}
@@ -0,0 +1,13 @@
1
+ let textDecoder = null;
2
+ export const decode = (dataView) => {
3
+ if ('TextDecoder' in self) {
4
+ if (textDecoder === null) {
5
+ textDecoder = new TextDecoder();
6
+ }
7
+ return textDecoder.decode(dataView);
8
+ }
9
+ // @todo Add an expectation test to check if this fallback is still necessary.
10
+ // String.fromCharCode() does normally expect numbers but it can also handle a typed array.
11
+ return String.fromCharCode.apply(null, new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));
12
+ };
13
+ //# sourceMappingURL=decode.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode.js","sourceRoot":"","sources":["../../../src/helpers/decode.ts"],"names":[],"mappings":"AAAA,IAAI,WAAW,GAAuB,IAAI,CAAC;AAE3C,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,QAAkB,EAAE,EAAE;IACzC,IAAI,aAAa,IAAI,IAAI,EAAE;QACvB,IAAI,WAAW,KAAK,IAAI,EAAE;YACtB,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;SACnC;QAED,OAAO,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;KACvC;IAED,8EAA8E;IAC9E,2FAA2F;IAC3F,OAAO,MAAM,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAkB,IAAI,UAAU,CAAC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,UAAU,EAAE,QAAQ,CAAC,UAAU,CAAE,CAAC,CAAC;AACvI,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const locate: (arrayBuffer: ArrayBuffer) => [number, number][];
2
+ //# sourceMappingURL=locate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate.d.ts","sourceRoot":"","sources":["../../../src/helpers/locate.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM,gBAAiB,WAAW,uBAsG9C,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { decode as decodeSynchsafe } from 'synchsafe';
2
+ import { decode as decodeString } from './decode';
3
+ export const locate = (arrayBuffer) => {
4
+ const locations = [];
5
+ let dataView = new DataView(arrayBuffer, 0, 4);
6
+ if (decodeString(dataView) === 'fLaC') {
7
+ let isLast = false;
8
+ let length = 0;
9
+ let offset = 4;
10
+ while (!isLast) {
11
+ offset += length;
12
+ dataView = new DataView(arrayBuffer, offset, 4);
13
+ isLast = (dataView.getUint8(0) & 0x80) !== 0; // tslint:disable-line:no-bitwise
14
+ length = (dataView.getUint8(3) | (dataView.getUint8(2) << 8) | (dataView.getUint8(1) << 16)) + 4; // tslint:disable-line:max-line-length no-bitwise
15
+ }
16
+ locations.push([0, offset + length]);
17
+ }
18
+ dataView = new DataView(arrayBuffer, 4, 4);
19
+ if (decodeString(dataView) === 'ftyp') {
20
+ let offset = 0;
21
+ while (offset < arrayBuffer.byteLength) {
22
+ dataView = new DataView(arrayBuffer, offset, 4);
23
+ const length = dataView.getUint32(0);
24
+ dataView = new DataView(arrayBuffer, offset + 4, 4);
25
+ const atom = decodeString(dataView);
26
+ if (atom === 'moov' || atom === 'wide') {
27
+ locations.push([offset, offset + length]);
28
+ }
29
+ offset += length;
30
+ }
31
+ }
32
+ dataView = new DataView(arrayBuffer, 0, 3);
33
+ if (decodeString(dataView) === 'ID3') {
34
+ dataView = new DataView(arrayBuffer, 6, 4);
35
+ locations.push([0, decodeSynchsafe(dataView.getUint32(0)) + 10]);
36
+ }
37
+ dataView = new DataView(arrayBuffer, 0, 4);
38
+ if (decodeString(dataView) === 'OggS') {
39
+ let offset = 0;
40
+ dataView = new DataView(arrayBuffer, 4, 1);
41
+ const streamStructureVersion = dataView.getUint8(0);
42
+ while (streamStructureVersion === 0 && offset < arrayBuffer.byteLength) {
43
+ dataView = new DataView(arrayBuffer, offset + 5, 22);
44
+ /* @todo Make sure the headerTypeFlag is not indicating that this is the first or last
45
+ * page. If so the surrounding pages would need to get an updated headerTypeFlag when
46
+ * stripping the metadata.
47
+ * headerTypeFlag = dataView.getUint8(0);
48
+ */
49
+ const pageSegments = dataView.getUint8(21);
50
+ dataView = new DataView(arrayBuffer, offset + 27, pageSegments + 1);
51
+ let pageSize = 27 + pageSegments;
52
+ for (let i = 0; i < pageSegments; i += 1) {
53
+ pageSize += dataView.getUint8(i);
54
+ }
55
+ const firstByte = dataView.getUint8(pageSegments);
56
+ if (firstByte === 3) {
57
+ dataView = new DataView(arrayBuffer, offset + 27 + pageSegments + 1, 6);
58
+ const identifier = decodeString(dataView);
59
+ if (identifier === 'vorbis') {
60
+ locations.push([offset, offset + pageSize]);
61
+ }
62
+ }
63
+ offset += pageSize;
64
+ }
65
+ }
66
+ dataView = new DataView(arrayBuffer, arrayBuffer.byteLength - 128, 3);
67
+ if (decodeString(dataView) === 'TAG') {
68
+ locations.push([arrayBuffer.byteLength - 128, arrayBuffer.byteLength]);
69
+ }
70
+ return locations;
71
+ };
72
+ //# sourceMappingURL=locate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate.js","sourceRoot":"","sources":["../../../src/helpers/locate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,UAAU,CAAC;AAElD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,WAAwB,EAAE,EAAE;IAC/C,MAAM,SAAS,GAAuB,EAA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@ -0,0 +1 @@
1
+ {"version":3,"file":"strip.d.ts","sourceRoot":"","sources":["../../../src/helpers/strip.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,gBAAiB,WAAW,gBAsB7C,CAAC"}
@@ -0,0 +1,21 @@
1
+ import { concat } from './concat';
2
+ import { locate } from './locate';
3
+ export const strip = (arrayBuffer) => {
4
+ const locations = locate(arrayBuffer);
5
+ let offset = 0;
6
+ let strippedArrayBuffer = arrayBuffer;
7
+ locations.forEach(([begin, end]) => {
8
+ if (begin === offset) {
9
+ strippedArrayBuffer = strippedArrayBuffer.slice(end, strippedArrayBuffer.byteLength);
10
+ }
11
+ else if (end - offset === strippedArrayBuffer.byteLength) {
12
+ strippedArrayBuffer = strippedArrayBuffer.slice(0, begin - offset);
13
+ }
14
+ else {
15
+ strippedArrayBuffer = concat(strippedArrayBuffer.slice(0, begin - offset), strippedArrayBuffer.slice(end - offset, strippedArrayBuffer.byteLength));
16
+ }
17
+ offset += end - begin;
18
+ });
19
+ return strippedArrayBuffer;
20
+ };
21
+ //# sourceMappingURL=strip.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip.js","sourceRoot":"","sources":["../../../src/helpers/strip.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,WAAwB,EAAE,EAAE;IAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IAEtC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,mBAAmB,GAAG,WAAW,CAAC;IAEtC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,EAAE;QAC/B,IAAI,KAAK,KAAK,MAAM,EAAE;YAClB,mBAAmB,GAAG,mBAAmB,CAAC,KAAK,CAAC,GAAG,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAAC;SACxF;aAAM,IAAI,GAAG,GAAG,MAAM,KAAK,mBAAmB,CAAC,UAAU,EAAE;YACxD,mBAAmB,GAAG,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,CAAC;SACtE;aAAM;YACH,mBAAmB,GAAG,MAAM,CACxB,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,EAC5C,mBAAmB,CAAC,KAAK,CAAC,GAAG,GAAG,MAAM,EAAE,mBAAmB,CAAC,UAAU,CAAC,CAC1E,CAAC;SACL;QAED,MAAM,IAAI,GAAG,GAAG,KAAK,CAAC;IAC1B,CAAC,CAAC,CAAC;IAEH,OAAO,mBAAmB,CAAC;AAC/B,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { TBrokerMessage } from '../types';
2
+ export interface IBrokerEvent extends Event {
3
+ data: TBrokerMessage;
4
+ }
5
+ //# sourceMappingURL=broker-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-event.d.ts","sourceRoot":"","sources":["../../../src/interfaces/broker-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,YAAa,SAAQ,KAAK;IACvC,IAAI,EAAE,cAAc,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=broker-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-event.js","sourceRoot":"","sources":["../../../src/interfaces/broker-event.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export interface IErrorResponse {
2
+ error: {
3
+ message: string;
4
+ };
5
+ id: number;
6
+ result: null;
7
+ }
8
+ //# sourceMappingURL=error-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-response.d.ts","sourceRoot":"","sources":["../../../src/interfaces/error-response.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC3B,KAAK,EAAE;QACH,OAAO,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,IAAI,CAAC;CAChB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=error-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-response.js","sourceRoot":"","sources":["../../../src/interfaces/error-response.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export * from './broker-event';
2
+ export * from './error-response';
3
+ export * from './locate-request';
4
+ export * from './locate-response';
5
+ export * from './strip-request';
6
+ export * from './strip-response';
7
+ export * from './worker-event';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export * from './broker-event';
2
+ export * from './error-response';
3
+ export * from './locate-request';
4
+ export * from './locate-response';
5
+ export * from './strip-request';
6
+ export * from './strip-response';
7
+ export * from './worker-event';
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,gBAAgB,CAAC"}
@@ -0,0 +1,8 @@
1
+ export interface ILocateRequest {
2
+ id: number;
3
+ method: 'locate';
4
+ params: {
5
+ arrayBuffer: ArrayBuffer;
6
+ };
7
+ }
8
+ //# sourceMappingURL=locate-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate-request.d.ts","sourceRoot":"","sources":["../../../src/interfaces/locate-request.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,QAAQ,CAAC;IAEjB,MAAM,EAAE;QACJ,WAAW,EAAE,WAAW,CAAC;KAC5B,CAAC;CACL"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=locate-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate-request.js","sourceRoot":"","sources":["../../../src/interfaces/locate-request.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export interface ILocateResponse {
2
+ error: null;
3
+ id: number;
4
+ result: {
5
+ locations: [number, number][];
6
+ };
7
+ }
8
+ //# sourceMappingURL=locate-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate-response.d.ts","sourceRoot":"","sources":["../../../src/interfaces/locate-response.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B,KAAK,EAAE,IAAI,CAAC;IAEZ,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE;QACJ,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC;KACjC,CAAC;CACL"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=locate-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locate-response.js","sourceRoot":"","sources":["../../../src/interfaces/locate-response.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export interface IStripRequest {
2
+ id: number;
3
+ method: 'strip';
4
+ params: {
5
+ arrayBuffer: ArrayBuffer;
6
+ };
7
+ }
8
+ //# sourceMappingURL=strip-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-request.d.ts","sourceRoot":"","sources":["../../../src/interfaces/strip-request.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,aAAa;IAC1B,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE,OAAO,CAAC;IAEhB,MAAM,EAAE;QACJ,WAAW,EAAE,WAAW,CAAC;KAC5B,CAAC;CACL"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=strip-request.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-request.js","sourceRoot":"","sources":["../../../src/interfaces/strip-request.ts"],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ export interface IStripResponse {
2
+ error: null;
3
+ id: number;
4
+ result: {
5
+ arrayBuffer: ArrayBuffer;
6
+ };
7
+ }
8
+ //# sourceMappingURL=strip-response.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-response.d.ts","sourceRoot":"","sources":["../../../src/interfaces/strip-response.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,cAAc;IAC3B,KAAK,EAAE,IAAI,CAAC;IAEZ,EAAE,EAAE,MAAM,CAAC;IAEX,MAAM,EAAE;QACJ,WAAW,EAAE,WAAW,CAAC;KAC5B,CAAC;CACL"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=strip-response.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip-response.js","sourceRoot":"","sources":["../../../src/interfaces/strip-response.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ import { TWorkerMessage } from '../types';
2
+ export interface IWorkerEvent extends Event {
3
+ data: TWorkerMessage;
4
+ }
5
+ //# sourceMappingURL=worker-event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-event.d.ts","sourceRoot":"","sources":["../../../src/interfaces/worker-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,YAAa,SAAQ,KAAK;IACvC,IAAI,EAAE,cAAc,CAAC;CACxB"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=worker-event.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-event.js","sourceRoot":"","sources":["../../../src/interfaces/worker-event.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './interfaces/index';
2
+ export * from './types/index';
3
+ //# sourceMappingURL=module.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAQA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { locate } from './helpers/locate';
2
+ import { strip } from './helpers/strip';
3
+ /*
4
+ * @todo Explicitly referencing the barrel file seems to be necessary when enabling the
5
+ * isolatedModules compiler option.
6
+ */
7
+ export * from './interfaces/index';
8
+ export * from './types/index';
9
+ addEventListener('message', ({ data }) => {
10
+ try {
11
+ if (data.method === 'locate') {
12
+ const { id, params: { arrayBuffer } } = data;
13
+ const locations = locate(arrayBuffer);
14
+ postMessage({
15
+ error: null,
16
+ id,
17
+ result: { locations }
18
+ });
19
+ }
20
+ else if (data.method === 'strip') {
21
+ const { id, params: { arrayBuffer } } = data;
22
+ const strippedArrayBuffer = strip(arrayBuffer);
23
+ postMessage({
24
+ error: null,
25
+ id,
26
+ result: { arrayBuffer: strippedArrayBuffer }
27
+ }, [strippedArrayBuffer]);
28
+ }
29
+ }
30
+ catch (err) {
31
+ postMessage({
32
+ error: {
33
+ message: err.message
34
+ },
35
+ id: data.id,
36
+ result: null
37
+ });
38
+ }
39
+ });
40
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAGxC;;;GAGG;AACH,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAE9B,gBAAgB,CAAC,SAAS,EAAE,CAAC,EAAE,IAAI,EAAgB,EAAE,EAAE;IACnD,IAAI;QACA,IAAI,IAAI,CAAC,MAAM,KAAK,QAAQ,EAAE;YAC1B,MAAM,EACF,EAAE,EACF,MAAM,EAAE,EAAE,WAAW,EAAE,EAC1B,GAAG,IAAI,CAAC;YAET,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;YAEtC,WAAW,CAAkB;gBACzB,KAAK,EAAE,IAAI;gBACX,EAAE;gBACF,MAAM,EAAE,EAAE,SAAS,EAAE;aACxB,CAAC,CAAC;SACN;aAAM,IAAI,IAAI,CAAC,MAAM,KAAK,OAAO,EAAE;YAChC,MAAM,EACF,EAAE,EACF,MAAM,EAAE,EAAE,WAAW,EAAE,EAC1B,GAAG,IAAI,CAAC;YAET,MAAM,mBAAmB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;YAE/C,WAAW,CACS;gBACZ,KAAK,EAAE,IAAI;gBACX,EAAE;gBACF,MAAM,EAAE,EAAE,WAAW,EAAE,mBAAmB,EAAE;aAC/C,EACD,CAAC,mBAAmB,CAAC,CACxB,CAAC;SACL;KACJ;IAAC,OAAO,GAAG,EAAE;QACV,WAAW,CAAiB;YACxB,KAAK,EAAE;gBACH,OAAO,EAAE,GAAG,CAAC,OAAO;aACvB;YACD,EAAE,EAAE,IAAI,CAAC,EAAE;YACX,MAAM,EAAE,IAAI;SACf,CAAC,CAAC;KACN;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { ILocateRequest, IStripRequest } from '../interfaces';
2
+ export declare type TBrokerMessage = ILocateRequest | IStripRequest;
3
+ //# sourceMappingURL=broker-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-message.d.ts","sourceRoot":"","sources":["../../../src/types/broker-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9D,oBAAY,cAAc,GAAG,cAAc,GAAG,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=broker-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"broker-message.js","sourceRoot":"","sources":["../../../src/types/broker-message.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export * from './broker-message';
2
+ export * from './worker-message';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './broker-message';
2
+ export * from './worker-message';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { IErrorResponse, ILocateResponse, IStripResponse } from '../interfaces';
2
+ export declare type TWorkerMessage = IErrorResponse | ILocateResponse | IStripResponse;
3
+ //# sourceMappingURL=worker-message.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-message.d.ts","sourceRoot":"","sources":["../../../src/types/worker-message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEhF,oBAAY,cAAc,GAAG,cAAc,GAAG,eAAe,GAAG,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=worker-message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worker-message.js","sourceRoot":"","sources":["../../../src/types/worker-message.ts"],"names":[],"mappings":""}
@@ -0,0 +1,202 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('synchsafe'), require('@babel/runtime/helpers/slicedToArray')) :
3
+ typeof define === 'function' && define.amd ? define(['synchsafe', '@babel/runtime/helpers/slicedToArray'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.synchsafe, global._slicedToArray));
5
+ }(this, (function (synchsafe, _slicedToArray) { 'use strict';
6
+
7
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
+
9
+ var _slicedToArray__default = /*#__PURE__*/_interopDefaultLegacy(_slicedToArray);
10
+
11
+ var textDecoder = null;
12
+ var decode = function decode(dataView) {
13
+ if ('TextDecoder' in self) {
14
+ if (textDecoder === null) {
15
+ textDecoder = new TextDecoder();
16
+ }
17
+
18
+ return textDecoder.decode(dataView);
19
+ } // @todo Add an expectation test to check if this fallback is still necessary.
20
+ // String.fromCharCode() does normally expect numbers but it can also handle a typed array.
21
+
22
+
23
+ return String.fromCharCode.apply(null, new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength));
24
+ };
25
+
26
+ var locate = function locate(arrayBuffer) {
27
+ var locations = [];
28
+ var dataView = new DataView(arrayBuffer, 0, 4);
29
+
30
+ if (decode(dataView) === 'fLaC') {
31
+ var isLast = false;
32
+ var length = 0;
33
+ var offset = 4;
34
+
35
+ while (!isLast) {
36
+ offset += length;
37
+ dataView = new DataView(arrayBuffer, offset, 4);
38
+ isLast = (dataView.getUint8(0) & 0x80) !== 0; // tslint:disable-line:no-bitwise
39
+
40
+ length = (dataView.getUint8(3) | dataView.getUint8(2) << 8 | dataView.getUint8(1) << 16) + 4; // tslint:disable-line:max-line-length no-bitwise
41
+ }
42
+
43
+ locations.push([0, offset + length]);
44
+ }
45
+
46
+ dataView = new DataView(arrayBuffer, 4, 4);
47
+
48
+ if (decode(dataView) === 'ftyp') {
49
+ var _offset = 0;
50
+
51
+ while (_offset < arrayBuffer.byteLength) {
52
+ dataView = new DataView(arrayBuffer, _offset, 4);
53
+
54
+ var _length = dataView.getUint32(0);
55
+
56
+ dataView = new DataView(arrayBuffer, _offset + 4, 4);
57
+ var atom = decode(dataView);
58
+
59
+ if (atom === 'moov' || atom === 'wide') {
60
+ locations.push([_offset, _offset + _length]);
61
+ }
62
+
63
+ _offset += _length;
64
+ }
65
+ }
66
+
67
+ dataView = new DataView(arrayBuffer, 0, 3);
68
+
69
+ if (decode(dataView) === 'ID3') {
70
+ dataView = new DataView(arrayBuffer, 6, 4);
71
+ locations.push([0, synchsafe.decode(dataView.getUint32(0)) + 10]);
72
+ }
73
+
74
+ dataView = new DataView(arrayBuffer, 0, 4);
75
+
76
+ if (decode(dataView) === 'OggS') {
77
+ var _offset2 = 0;
78
+ dataView = new DataView(arrayBuffer, 4, 1);
79
+ var streamStructureVersion = dataView.getUint8(0);
80
+
81
+ while (streamStructureVersion === 0 && _offset2 < arrayBuffer.byteLength) {
82
+ dataView = new DataView(arrayBuffer, _offset2 + 5, 22);
83
+ /* @todo Make sure the headerTypeFlag is not indicating that this is the first or last
84
+ * page. If so the surrounding pages would need to get an updated headerTypeFlag when
85
+ * stripping the metadata.
86
+ * headerTypeFlag = dataView.getUint8(0);
87
+ */
88
+
89
+ var pageSegments = dataView.getUint8(21);
90
+ dataView = new DataView(arrayBuffer, _offset2 + 27, pageSegments + 1);
91
+ var pageSize = 27 + pageSegments;
92
+
93
+ for (var i = 0; i < pageSegments; i += 1) {
94
+ pageSize += dataView.getUint8(i);
95
+ }
96
+
97
+ var firstByte = dataView.getUint8(pageSegments);
98
+
99
+ if (firstByte === 3) {
100
+ dataView = new DataView(arrayBuffer, _offset2 + 27 + pageSegments + 1, 6);
101
+ var identifier = decode(dataView);
102
+
103
+ if (identifier === 'vorbis') {
104
+ locations.push([_offset2, _offset2 + pageSize]);
105
+ }
106
+ }
107
+
108
+ _offset2 += pageSize;
109
+ }
110
+ }
111
+
112
+ dataView = new DataView(arrayBuffer, arrayBuffer.byteLength - 128, 3);
113
+
114
+ if (decode(dataView) === 'TAG') {
115
+ locations.push([arrayBuffer.byteLength - 128, arrayBuffer.byteLength]);
116
+ }
117
+
118
+ return locations;
119
+ };
120
+
121
+ var concat = function concat() {
122
+ for (var _len = arguments.length, arrayBuffers = new Array(_len), _key = 0; _key < _len; _key++) {
123
+ arrayBuffers[_key] = arguments[_key];
124
+ }
125
+
126
+ return arrayBuffers.reduce(function (_ref, arrayBuffer) {
127
+ var array = _ref.array,
128
+ offset = _ref.offset;
129
+ array.set(new Uint8Array(arrayBuffer), offset);
130
+ return {
131
+ array: array,
132
+ offset: offset + arrayBuffer.byteLength
133
+ };
134
+ }, {
135
+ array: new Uint8Array(arrayBuffers.reduce(function (byteLength, arrayBuffer) {
136
+ return byteLength + arrayBuffer.byteLength;
137
+ }, 0)),
138
+ offset: 0
139
+ }).array.buffer;
140
+ };
141
+
142
+ var strip = function strip(arrayBuffer) {
143
+ var locations = locate(arrayBuffer);
144
+ var offset = 0;
145
+ var strippedArrayBuffer = arrayBuffer;
146
+ locations.forEach(function (_ref) {
147
+ var _ref2 = _slicedToArray__default['default'](_ref, 2),
148
+ begin = _ref2[0],
149
+ end = _ref2[1];
150
+
151
+ if (begin === offset) {
152
+ strippedArrayBuffer = strippedArrayBuffer.slice(end, strippedArrayBuffer.byteLength);
153
+ } else if (end - offset === strippedArrayBuffer.byteLength) {
154
+ strippedArrayBuffer = strippedArrayBuffer.slice(0, begin - offset);
155
+ } else {
156
+ strippedArrayBuffer = concat(strippedArrayBuffer.slice(0, begin - offset), strippedArrayBuffer.slice(end - offset, strippedArrayBuffer.byteLength));
157
+ }
158
+
159
+ offset += end - begin;
160
+ });
161
+ return strippedArrayBuffer;
162
+ };
163
+
164
+ addEventListener('message', function (_ref) {
165
+ var data = _ref.data;
166
+
167
+ try {
168
+ if (data.method === 'locate') {
169
+ var id = data.id,
170
+ arrayBuffer = data.params.arrayBuffer;
171
+ var locations = locate(arrayBuffer);
172
+ postMessage({
173
+ error: null,
174
+ id: id,
175
+ result: {
176
+ locations: locations
177
+ }
178
+ });
179
+ } else if (data.method === 'strip') {
180
+ var _id = data.id,
181
+ _arrayBuffer = data.params.arrayBuffer;
182
+ var strippedArrayBuffer = strip(_arrayBuffer);
183
+ postMessage({
184
+ error: null,
185
+ id: _id,
186
+ result: {
187
+ arrayBuffer: strippedArrayBuffer
188
+ }
189
+ }, [strippedArrayBuffer]);
190
+ }
191
+ } catch (err) {
192
+ postMessage({
193
+ error: {
194
+ message: err.message
195
+ },
196
+ id: data.id,
197
+ result: null
198
+ });
199
+ }
200
+ });
201
+
202
+ })));
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "author": "Christoph Guttandin",
3
+ "bugs": {
4
+ "url": "https://github.com/chrisguttandin/metadata-detector-worker/issues"
5
+ },
6
+ "config": {
7
+ "commitizen": {
8
+ "path": "cz-conventional-changelog"
9
+ }
10
+ },
11
+ "dependencies": {
12
+ "@babel/runtime": "^7.15.4",
13
+ "synchsafe": "^6.0.6",
14
+ "tslib": "^2.3.1"
15
+ },
16
+ "description": "The worker which is used by the metadata-detector package.",
17
+ "devDependencies": {
18
+ "@babel/core": "^7.15.5",
19
+ "@babel/plugin-external-helpers": "^7.14.5",
20
+ "@babel/plugin-transform-runtime": "^7.15.0",
21
+ "@babel/preset-env": "^7.15.6",
22
+ "@commitlint/cli": "^13.1.0",
23
+ "@commitlint/config-angular": "^13.1.0",
24
+ "@rollup/plugin-babel": "^5.3.0",
25
+ "chai": "^4.3.4",
26
+ "commitizen": "^4.2.4",
27
+ "cz-conventional-changelog": "^3.3.0",
28
+ "eslint": "^7.32.0",
29
+ "eslint-config-holy-grail": "^50.1.8",
30
+ "grunt": "^1.4.1",
31
+ "grunt-cli": "^1.4.3",
32
+ "grunt-contrib-clean": "^2.0.0",
33
+ "grunt-sh": "^0.2.0",
34
+ "husky": "^7.0.2",
35
+ "karma": "^6.3.4",
36
+ "karma-browserstack-launcher": "^1.6.0",
37
+ "karma-chrome-launcher": "^3.1.0",
38
+ "karma-cli": "^2.0.0",
39
+ "karma-firefox-launcher": "^2.1.1",
40
+ "karma-leche": "^2.0.1",
41
+ "karma-mocha": "^2.0.1",
42
+ "karma-mocha-webworker": "^1.3.0",
43
+ "karma-safari-launcher": "^1.0.0",
44
+ "karma-sinon-chai": "^2.0.2",
45
+ "karma-webpack": "^5.0.0",
46
+ "load-grunt-config": "^4.0.1",
47
+ "memory-fs": "^0.5.0",
48
+ "mocha": "^9.1.1",
49
+ "prettier": "^2.4.1",
50
+ "pretty-quick": "^3.1.1",
51
+ "rollup": "^2.56.3",
52
+ "sinon": "^11.1.2",
53
+ "sinon-chai": "^3.7.0",
54
+ "ts-loader": "^9.2.5",
55
+ "tsconfig-holy-grail": "^11.1.12",
56
+ "tslint": "^6.1.3",
57
+ "tslint-config-holy-grail": "^53.2.25",
58
+ "typescript": "^4.4.3",
59
+ "webpack": "^5.53.0"
60
+ },
61
+ "files": [
62
+ "build/es2019/",
63
+ "build/es5/",
64
+ "src/"
65
+ ],
66
+ "homepage": "https://github.com/chrisguttandin/metadata-detector-worker",
67
+ "license": "MIT",
68
+ "main": "build/es5/bundle.js",
69
+ "module": "build/es2019/module.js",
70
+ "name": "metadata-detector-worker",
71
+ "repository": {
72
+ "type": "git",
73
+ "url": "https://github.com/chrisguttandin/metadata-detector-worker.git"
74
+ },
75
+ "scripts": {
76
+ "prepare": "husky install",
77
+ "prepublishOnly": "grunt build",
78
+ "test": "grunt lint && grunt test"
79
+ },
80
+ "types": "build/es2019/module.d.ts",
81
+ "version": "4.0.38"
82
+ }
@@ -0,0 +1,13 @@
1
+ export const concat = (...arrayBuffers: ArrayBuffer[]) => {
2
+ return <ArrayBuffer>arrayBuffers.reduce(
3
+ ({ array, offset }, arrayBuffer) => {
4
+ array.set(new Uint8Array(arrayBuffer), offset);
5
+
6
+ return { array, offset: offset + arrayBuffer.byteLength };
7
+ },
8
+ {
9
+ array: new Uint8Array(arrayBuffers.reduce((byteLength, arrayBuffer) => byteLength + arrayBuffer.byteLength, 0)),
10
+ offset: 0
11
+ }
12
+ ).array.buffer;
13
+ };
@@ -0,0 +1,15 @@
1
+ let textDecoder: null | TextDecoder = null;
2
+
3
+ export const decode = (dataView: DataView) => {
4
+ if ('TextDecoder' in self) {
5
+ if (textDecoder === null) {
6
+ textDecoder = new TextDecoder();
7
+ }
8
+
9
+ return textDecoder.decode(dataView);
10
+ }
11
+
12
+ // @todo Add an expectation test to check if this fallback is still necessary.
13
+ // String.fromCharCode() does normally expect numbers but it can also handle a typed array.
14
+ return String.fromCharCode.apply(null, <number[]>(<any>new Uint8Array(dataView.buffer, dataView.byteOffset, dataView.byteLength)));
15
+ };
@@ -0,0 +1,106 @@
1
+ import { decode as decodeSynchsafe } from 'synchsafe';
2
+ import { decode as decodeString } from './decode';
3
+
4
+ export const locate = (arrayBuffer: ArrayBuffer) => {
5
+ const locations: [number, number][] = [];
6
+
7
+ let dataView = new DataView(arrayBuffer, 0, 4);
8
+
9
+ if (decodeString(dataView) === 'fLaC') {
10
+ let isLast = false;
11
+ let length = 0;
12
+ let offset = 4;
13
+
14
+ while (!isLast) {
15
+ offset += length;
16
+
17
+ dataView = new DataView(arrayBuffer, offset, 4);
18
+
19
+ isLast = (dataView.getUint8(0) & 0x80) !== 0; // tslint:disable-line:no-bitwise
20
+ length = (dataView.getUint8(3) | (dataView.getUint8(2) << 8) | (dataView.getUint8(1) << 16)) + 4; // tslint:disable-line:max-line-length no-bitwise
21
+ }
22
+
23
+ locations.push([0, offset + length]);
24
+ }
25
+
26
+ dataView = new DataView(arrayBuffer, 4, 4);
27
+
28
+ if (decodeString(dataView) === 'ftyp') {
29
+ let offset = 0;
30
+
31
+ while (offset < arrayBuffer.byteLength) {
32
+ dataView = new DataView(arrayBuffer, offset, 4);
33
+
34
+ const length = dataView.getUint32(0);
35
+
36
+ dataView = new DataView(arrayBuffer, offset + 4, 4);
37
+
38
+ const atom = decodeString(dataView);
39
+
40
+ if (atom === 'moov' || atom === 'wide') {
41
+ locations.push([offset, offset + length]);
42
+ }
43
+
44
+ offset += length;
45
+ }
46
+ }
47
+
48
+ dataView = new DataView(arrayBuffer, 0, 3);
49
+
50
+ if (decodeString(dataView) === 'ID3') {
51
+ dataView = new DataView(arrayBuffer, 6, 4);
52
+
53
+ locations.push([0, decodeSynchsafe(dataView.getUint32(0)) + 10]);
54
+ }
55
+
56
+ dataView = new DataView(arrayBuffer, 0, 4);
57
+
58
+ if (decodeString(dataView) === 'OggS') {
59
+ let offset = 0;
60
+
61
+ dataView = new DataView(arrayBuffer, 4, 1);
62
+
63
+ const streamStructureVersion = dataView.getUint8(0);
64
+
65
+ while (streamStructureVersion === 0 && offset < arrayBuffer.byteLength) {
66
+ dataView = new DataView(arrayBuffer, offset + 5, 22);
67
+
68
+ /* @todo Make sure the headerTypeFlag is not indicating that this is the first or last
69
+ * page. If so the surrounding pages would need to get an updated headerTypeFlag when
70
+ * stripping the metadata.
71
+ * headerTypeFlag = dataView.getUint8(0);
72
+ */
73
+ const pageSegments = dataView.getUint8(21);
74
+
75
+ dataView = new DataView(arrayBuffer, offset + 27, pageSegments + 1);
76
+
77
+ let pageSize = 27 + pageSegments;
78
+
79
+ for (let i = 0; i < pageSegments; i += 1) {
80
+ pageSize += dataView.getUint8(i);
81
+ }
82
+
83
+ const firstByte = dataView.getUint8(pageSegments);
84
+
85
+ if (firstByte === 3) {
86
+ dataView = new DataView(arrayBuffer, offset + 27 + pageSegments + 1, 6);
87
+
88
+ const identifier = decodeString(dataView);
89
+
90
+ if (identifier === 'vorbis') {
91
+ locations.push([offset, offset + pageSize]);
92
+ }
93
+ }
94
+
95
+ offset += pageSize;
96
+ }
97
+ }
98
+
99
+ dataView = new DataView(arrayBuffer, arrayBuffer.byteLength - 128, 3);
100
+
101
+ if (decodeString(dataView) === 'TAG') {
102
+ locations.push([arrayBuffer.byteLength - 128, arrayBuffer.byteLength]);
103
+ }
104
+
105
+ return locations;
106
+ };
@@ -0,0 +1,26 @@
1
+ import { concat } from './concat';
2
+ import { locate } from './locate';
3
+
4
+ export const strip = (arrayBuffer: ArrayBuffer) => {
5
+ const locations = locate(arrayBuffer);
6
+
7
+ let offset = 0;
8
+ let strippedArrayBuffer = arrayBuffer;
9
+
10
+ locations.forEach(([begin, end]) => {
11
+ if (begin === offset) {
12
+ strippedArrayBuffer = strippedArrayBuffer.slice(end, strippedArrayBuffer.byteLength);
13
+ } else if (end - offset === strippedArrayBuffer.byteLength) {
14
+ strippedArrayBuffer = strippedArrayBuffer.slice(0, begin - offset);
15
+ } else {
16
+ strippedArrayBuffer = concat(
17
+ strippedArrayBuffer.slice(0, begin - offset),
18
+ strippedArrayBuffer.slice(end - offset, strippedArrayBuffer.byteLength)
19
+ );
20
+ }
21
+
22
+ offset += end - begin;
23
+ });
24
+
25
+ return strippedArrayBuffer;
26
+ };
@@ -0,0 +1,5 @@
1
+ import { TBrokerMessage } from '../types';
2
+
3
+ export interface IBrokerEvent extends Event {
4
+ data: TBrokerMessage;
5
+ }
@@ -0,0 +1,9 @@
1
+ export interface IErrorResponse {
2
+ error: {
3
+ message: string;
4
+ };
5
+
6
+ id: number;
7
+
8
+ result: null;
9
+ }
@@ -0,0 +1,7 @@
1
+ export * from './broker-event';
2
+ export * from './error-response';
3
+ export * from './locate-request';
4
+ export * from './locate-response';
5
+ export * from './strip-request';
6
+ export * from './strip-response';
7
+ export * from './worker-event';
@@ -0,0 +1,9 @@
1
+ export interface ILocateRequest {
2
+ id: number;
3
+
4
+ method: 'locate';
5
+
6
+ params: {
7
+ arrayBuffer: ArrayBuffer;
8
+ };
9
+ }
@@ -0,0 +1,9 @@
1
+ export interface ILocateResponse {
2
+ error: null;
3
+
4
+ id: number;
5
+
6
+ result: {
7
+ locations: [number, number][];
8
+ };
9
+ }
@@ -0,0 +1,9 @@
1
+ export interface IStripRequest {
2
+ id: number;
3
+
4
+ method: 'strip';
5
+
6
+ params: {
7
+ arrayBuffer: ArrayBuffer;
8
+ };
9
+ }
@@ -0,0 +1,9 @@
1
+ export interface IStripResponse {
2
+ error: null;
3
+
4
+ id: number;
5
+
6
+ result: {
7
+ arrayBuffer: ArrayBuffer;
8
+ };
9
+ }
@@ -0,0 +1,5 @@
1
+ import { TWorkerMessage } from '../types';
2
+
3
+ export interface IWorkerEvent extends Event {
4
+ data: TWorkerMessage;
5
+ }
package/src/module.ts ADDED
@@ -0,0 +1,53 @@
1
+ import { locate } from './helpers/locate';
2
+ import { strip } from './helpers/strip';
3
+ import { IBrokerEvent, IErrorResponse, ILocateResponse, IStripResponse } from './interfaces';
4
+
5
+ /*
6
+ * @todo Explicitly referencing the barrel file seems to be necessary when enabling the
7
+ * isolatedModules compiler option.
8
+ */
9
+ export * from './interfaces/index';
10
+ export * from './types/index';
11
+
12
+ addEventListener('message', ({ data }: IBrokerEvent) => {
13
+ try {
14
+ if (data.method === 'locate') {
15
+ const {
16
+ id,
17
+ params: { arrayBuffer }
18
+ } = data;
19
+
20
+ const locations = locate(arrayBuffer);
21
+
22
+ postMessage(<ILocateResponse>{
23
+ error: null,
24
+ id,
25
+ result: { locations }
26
+ });
27
+ } else if (data.method === 'strip') {
28
+ const {
29
+ id,
30
+ params: { arrayBuffer }
31
+ } = data;
32
+
33
+ const strippedArrayBuffer = strip(arrayBuffer);
34
+
35
+ postMessage(
36
+ <IStripResponse>{
37
+ error: null,
38
+ id,
39
+ result: { arrayBuffer: strippedArrayBuffer }
40
+ },
41
+ [strippedArrayBuffer]
42
+ );
43
+ }
44
+ } catch (err) {
45
+ postMessage(<IErrorResponse>{
46
+ error: {
47
+ message: err.message
48
+ },
49
+ id: data.id,
50
+ result: null
51
+ });
52
+ }
53
+ });
@@ -0,0 +1,6 @@
1
+ {
2
+ "compilerOptions": {
3
+ "isolatedModules": true
4
+ },
5
+ "extends": "tsconfig-holy-grail/src/tsconfig-web-worker"
6
+ }
@@ -0,0 +1,3 @@
1
+ import { ILocateRequest, IStripRequest } from '../interfaces';
2
+
3
+ export type TBrokerMessage = ILocateRequest | IStripRequest;
@@ -0,0 +1,2 @@
1
+ export * from './broker-message';
2
+ export * from './worker-message';
@@ -0,0 +1,3 @@
1
+ import { IErrorResponse, ILocateResponse, IStripResponse } from '../interfaces';
2
+
3
+ export type TWorkerMessage = IErrorResponse | ILocateResponse | IStripResponse;