echogarden 1.8.6 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -18
- package/data/schemas/options.json +52 -47
- package/dist/alignment/DTWSequenceAlignment.d.ts +1 -1
- package/dist/alignment/DTWSequenceAlignment.js +5 -5
- package/dist/alignment/DTWSequenceAlignment.js.map +1 -1
- package/dist/alignment/SpeechAlignment.js +6 -6
- package/dist/alignment/SpeechAlignment.js.map +1 -1
- package/dist/api/Alignment.d.ts +1 -1
- package/dist/api/Alignment.js +49 -11
- package/dist/api/Alignment.js.map +1 -1
- package/dist/api/Denoising.d.ts +4 -2
- package/dist/api/Denoising.js +65 -13
- package/dist/api/Denoising.js.map +1 -1
- package/dist/api/SourceSeparation.js +9 -6
- package/dist/api/SourceSeparation.js.map +1 -1
- package/dist/api/SpeechLanguageDetection.js +4 -4
- package/dist/api/SpeechLanguageDetection.js.map +1 -1
- package/dist/api/Synthesis.d.ts +2 -2
- package/dist/api/Synthesis.js +10 -7
- package/dist/api/Synthesis.js.map +1 -1
- package/dist/api/VoiceActivityDetection.js +2 -2
- package/dist/api/VoiceActivityDetection.js.map +1 -1
- package/dist/audio/AudioBufferConversion.d.ts +2 -2
- package/dist/audio/AudioBufferConversion.js +77 -43
- package/dist/audio/AudioBufferConversion.js.map +1 -1
- package/dist/audio/AudioPlayer.d.ts +7 -5
- package/dist/audio/AudioPlayer.js +136 -50
- package/dist/audio/AudioPlayer.js.map +1 -1
- package/dist/audio/AudioUtilities.d.ts +4 -3
- package/dist/audio/AudioUtilities.js +30 -15
- package/dist/audio/AudioUtilities.js.map +1 -1
- package/dist/audio/SoxPath.js +3 -3
- package/dist/audio/SoxPath.js.map +1 -1
- package/dist/build-tools/MakeTarballsForInstalledPackages.js +3 -3
- package/dist/build-tools/MakeTarballsForInstalledPackages.js.map +1 -1
- package/dist/cli/CLI.js +30 -36
- package/dist/cli/CLI.js.map +1 -1
- package/dist/cli/CLIConfigFile.js +2 -2
- package/dist/cli/CLIConfigFile.js.map +1 -1
- package/dist/cli/CLIOptions.d.ts +2 -0
- package/dist/cli/CLIOptions.js +1 -1
- package/dist/cli/CLIOptions.js.map +1 -1
- package/dist/codecs/FFMpegTranscoder.d.ts +3 -3
- package/dist/codecs/FFMpegTranscoder.js +6 -6
- package/dist/codecs/FFMpegTranscoder.js.map +1 -1
- package/dist/codecs/TIMITCodec.d.ts +1 -1
- package/dist/codecs/TIMITCodec.js +4 -3
- package/dist/codecs/TIMITCodec.js.map +1 -1
- package/dist/codecs/WaveCodec.d.ts +3 -3
- package/dist/codecs/WaveCodec.js +37 -34
- package/dist/codecs/WaveCodec.js.map +1 -1
- package/dist/data-structures/DynamicTypedArray.d.ts +17 -0
- package/dist/data-structures/DynamicTypedArray.js +47 -0
- package/dist/data-structures/DynamicTypedArray.js.map +1 -0
- package/dist/data-structures/Queue.js.map +1 -0
- package/dist/data-structures/WindowedList.js.map +1 -0
- package/dist/denoising/NSNet2.d.ts +26 -0
- package/dist/denoising/NSNet2.js +128 -0
- package/dist/denoising/NSNet2.js.map +1 -0
- package/dist/denoising/RNNoise.js +3 -3
- package/dist/denoising/RNNoise.js.map +1 -1
- package/dist/dsp/FFT.d.ts +6 -1
- package/dist/dsp/FFT.js +17 -0
- package/dist/dsp/FFT.js.map +1 -1
- package/dist/encodings/Ascii.d.ts +10 -0
- package/dist/encodings/Ascii.js +41 -0
- package/dist/encodings/Ascii.js.map +1 -0
- package/dist/encodings/Base64.d.ts +5 -0
- package/dist/encodings/Base64.js +114 -0
- package/dist/encodings/Base64.js.map +1 -0
- package/dist/encodings/Hex.d.ts +3 -0
- package/dist/encodings/Hex.js +52 -0
- package/dist/encodings/Hex.js.map +1 -0
- package/dist/{utilities → encodings}/LEB128.d.ts +1 -1
- package/dist/{utilities → encodings}/LEB128.js +4 -4
- package/dist/encodings/LEB128.js.map +1 -0
- package/dist/{utilities → encodings}/LPVarInt.d.ts +1 -1
- package/dist/{utilities → encodings}/LPVarInt.js +6 -6
- package/dist/encodings/LPVarInt.js.map +1 -0
- package/dist/encodings/TextEncodingsCommon.d.ts +4 -0
- package/dist/encodings/TextEncodingsCommon.js +2 -0
- package/dist/encodings/TextEncodingsCommon.js.map +1 -0
- package/dist/encodings/Utf16.d.ts +10 -0
- package/dist/encodings/Utf16.js +36 -0
- package/dist/encodings/Utf16.js.map +1 -0
- package/dist/encodings/Utf32.d.ts +9 -0
- package/dist/encodings/Utf32.js +44 -0
- package/dist/encodings/Utf32.js.map +1 -0
- package/dist/encodings/Utf8.d.ts +10 -0
- package/dist/encodings/Utf8.js +97 -0
- package/dist/encodings/Utf8.js.map +1 -0
- package/dist/math/MedianFilter.js.map +1 -1
- package/dist/nlp/JapaneseSegmentation.js +2 -2
- package/dist/nlp/JapaneseSegmentation.js.map +1 -1
- package/dist/recognition/GoogleCloudSTT.js +2 -1
- package/dist/recognition/GoogleCloudSTT.js.map +1 -1
- package/dist/recognition/SileroSTT.js +3 -3
- package/dist/recognition/SileroSTT.js.map +1 -1
- package/dist/recognition/VoskSTT.js +3 -3
- package/dist/recognition/VoskSTT.js.map +1 -1
- package/dist/recognition/WhisperCppSTT.js +4 -5
- package/dist/recognition/WhisperCppSTT.js.map +1 -1
- package/dist/recognition/WhisperSTT.js +8 -7
- package/dist/recognition/WhisperSTT.js.map +1 -1
- package/dist/server/Client.d.ts +1 -1
- package/dist/server/Client.js +2 -1
- package/dist/server/Client.js.map +1 -1
- package/dist/server/Server.js +5 -4
- package/dist/server/Server.js.map +1 -1
- package/dist/server/Worker.js +1 -1
- package/dist/server/Worker.js.map +1 -1
- package/dist/source-separation/MDXNetSourceSeparation.js +1 -1
- package/dist/source-separation/MDXNetSourceSeparation.js.map +1 -1
- package/dist/speech-search/DTWSpeechSearch.d.ts +1 -1
- package/dist/speech-search/DTWSpeechSearch.js +25 -6
- package/dist/speech-search/DTWSpeechSearch.js.map +1 -1
- package/dist/subtitles/Subtitles.js +2 -2
- package/dist/subtitles/Subtitles.js.map +1 -1
- package/dist/synthesis/AzureCognitiveServicesTTS.js +17 -18
- package/dist/synthesis/AzureCognitiveServicesTTS.js.map +1 -1
- package/dist/synthesis/CoquiServerTTS.js +1 -1
- package/dist/synthesis/CoquiServerTTS.js.map +1 -1
- package/dist/synthesis/ElevenlabsTTS.js +1 -1
- package/dist/synthesis/ElevenlabsTTS.js.map +1 -1
- package/dist/synthesis/EspeakTTS.d.ts +0 -1
- package/dist/synthesis/EspeakTTS.js +0 -9
- package/dist/synthesis/EspeakTTS.js.map +1 -1
- package/dist/synthesis/FliteTTS.js +7 -8
- package/dist/synthesis/FliteTTS.js.map +1 -1
- package/dist/synthesis/GoogleCloudTTS.d.ts +1 -1
- package/dist/synthesis/GoogleCloudTTS.js +2 -1
- package/dist/synthesis/GoogleCloudTTS.js.map +1 -1
- package/dist/synthesis/GoogleTranslateTTS.d.ts +1 -1
- package/dist/synthesis/GoogleTranslateTTS.js +4 -3
- package/dist/synthesis/GoogleTranslateTTS.js.map +1 -1
- package/dist/synthesis/MicrosoftEdgeTTS.js +32 -7
- package/dist/synthesis/MicrosoftEdgeTTS.js.map +1 -1
- package/dist/synthesis/SapiTTS.js +1 -1
- package/dist/synthesis/SapiTTS.js.map +1 -1
- package/dist/synthesis/StreamlabsPollyTTS.d.ts +1 -1
- package/dist/synthesis/StreamlabsPollyTTS.js +1 -1
- package/dist/synthesis/StreamlabsPollyTTS.js.map +1 -1
- package/dist/synthesis/SvoxPicoTTS.js +6 -5
- package/dist/synthesis/SvoxPicoTTS.js.map +1 -1
- package/dist/synthesis/VitsTTS.js +2 -2
- package/dist/synthesis/VitsTTS.js.map +1 -1
- package/dist/tests/Test.js +0 -25
- package/dist/tests/Test.js.map +1 -1
- package/dist/text-language-detection/FastTextLanguageDetection.js +2 -2
- package/dist/text-language-detection/FastTextLanguageDetection.js.map +1 -1
- package/dist/typings/TypedArray.d.ts +4 -0
- package/dist/typings/TypedArray.js +2 -0
- package/dist/typings/TypedArray.js.map +1 -0
- package/dist/utilities/BinaryArrayConversion.d.ts +12 -22
- package/dist/utilities/BinaryArrayConversion.js +40 -90
- package/dist/utilities/BinaryArrayConversion.js.map +1 -1
- package/dist/utilities/BinaryUtilities.d.ts +13 -0
- package/dist/utilities/BinaryUtilities.js +113 -0
- package/dist/utilities/BinaryUtilities.js.map +1 -0
- package/dist/utilities/Compression.js +7 -6
- package/dist/utilities/Compression.js.map +1 -1
- package/dist/utilities/FileDownloader.js +26 -47
- package/dist/utilities/FileDownloader.js.map +1 -1
- package/dist/utilities/FileReader.d.ts +14 -0
- package/dist/utilities/FileReader.js +71 -0
- package/dist/utilities/FileReader.js.map +1 -0
- package/dist/utilities/FileSystem.d.ts +19 -17
- package/dist/utilities/FileSystem.js +170 -106
- package/dist/utilities/FileSystem.js.map +1 -1
- package/dist/utilities/FileWriter.d.ts +12 -0
- package/dist/utilities/FileWriter.js +60 -0
- package/dist/utilities/FileWriter.js.map +1 -0
- package/dist/utilities/NpmUtilities.d.ts +1 -0
- package/dist/utilities/NpmUtilities.js +14 -0
- package/dist/utilities/NpmUtilities.js.map +1 -0
- package/dist/utilities/PackageManager.js +7 -5
- package/dist/utilities/PackageManager.js.map +1 -1
- package/dist/utilities/PathUtilities.d.ts +8 -0
- package/dist/utilities/PathUtilities.js +28 -7
- package/dist/utilities/PathUtilities.js.map +1 -1
- package/dist/utilities/SignalChannel.d.ts +3 -1
- package/dist/utilities/SignalChannel.js +9 -5
- package/dist/utilities/SignalChannel.js.map +1 -1
- package/dist/utilities/StringBuilder.d.ts +10 -0
- package/dist/utilities/StringBuilder.js +39 -0
- package/dist/utilities/StringBuilder.js.map +1 -0
- package/dist/utilities/StringUtilities.js.map +1 -1
- package/dist/utilities/TarballMaker.js +6 -7
- package/dist/utilities/TarballMaker.js.map +1 -1
- package/dist/utilities/Timer.js +2 -2
- package/dist/utilities/Timer.js.map +1 -1
- package/dist/utilities/Utilities.d.ts +11 -4
- package/dist/utilities/Utilities.js +70 -18
- package/dist/utilities/Utilities.js.map +1 -1
- package/dist/utilities/VirtualFileReadStream.d.ts +3 -3
- package/dist/utilities/VirtualFileReadStream.js.map +1 -1
- package/dist/utilities/WasmMemoryManager.d.ts +5 -2
- package/dist/utilities/WasmMemoryManager.js +15 -3
- package/dist/utilities/WasmMemoryManager.js.map +1 -1
- package/docs/API.md +1 -1
- package/docs/Licenses.md +3 -0
- package/docs/Options.md +9 -3
- package/docs/Tasklist.md +0 -1
- package/docs/Technical.md +2 -2
- package/package.json +20 -22
- package/src/alignment/DTWSequenceAlignment.ts +5 -5
- package/src/alignment/SpeechAlignment.ts +6 -6
- package/src/api/Alignment.ts +65 -12
- package/src/api/Denoising.ts +97 -17
- package/src/api/SourceSeparation.ts +11 -8
- package/src/api/SpeechLanguageDetection.ts +4 -4
- package/src/api/Synthesis.ts +15 -11
- package/src/api/VoiceActivityDetection.ts +2 -2
- package/src/audio/AudioBufferConversion.ts +84 -45
- package/src/audio/AudioPlayer.ts +156 -54
- package/src/audio/AudioUtilities.ts +38 -22
- package/src/audio/SoxPath.ts +3 -3
- package/src/build-tools/MakeTarballsForInstalledPackages.ts +3 -3
- package/src/cli/CLI.ts +30 -36
- package/src/cli/CLIConfigFile.ts +2 -2
- package/src/cli/CLIOptions.ts +4 -1
- package/src/codecs/FFMpegTranscoder.ts +11 -11
- package/src/codecs/TIMITCodec.ts +5 -4
- package/src/codecs/WaveCodec.ts +42 -39
- package/src/data-structures/DynamicTypedArray.ts +64 -0
- package/src/denoising/NSNet2.ts +182 -0
- package/src/denoising/RNNoise.ts +3 -3
- package/src/dsp/FFT.ts +21 -1
- package/src/encodings/Ascii.ts +60 -0
- package/src/encodings/Base64.ts +157 -0
- package/src/encodings/Hex.ts +67 -0
- package/src/{utilities → encodings}/LEB128.ts +4 -4
- package/src/{utilities → encodings}/LPVarInt.ts +6 -6
- package/src/encodings/TextEncodingsCommon.ts +4 -0
- package/src/encodings/Utf16.ts +52 -0
- package/src/encodings/Utf32.ts +62 -0
- package/src/encodings/Utf8.ts +117 -0
- package/src/math/MedianFilter.ts +0 -2
- package/src/nlp/JapaneseSegmentation.ts +2 -2
- package/src/recognition/GoogleCloudSTT.ts +2 -1
- package/src/recognition/SileroSTT.ts +3 -3
- package/src/recognition/VoskSTT.ts +3 -3
- package/src/recognition/WhisperCppSTT.ts +4 -5
- package/src/recognition/WhisperSTT.ts +8 -7
- package/src/server/Client.ts +4 -3
- package/src/server/Server.ts +6 -5
- package/src/server/Worker.ts +1 -1
- package/src/source-separation/MDXNetSourceSeparation.ts +1 -1
- package/src/speech-search/DTWSpeechSearch.ts +36 -7
- package/src/subtitles/Subtitles.ts +3 -3
- package/src/synthesis/AzureCognitiveServicesTTS.ts +18 -15
- package/src/synthesis/CoquiServerTTS.ts +2 -2
- package/src/synthesis/ElevenlabsTTS.ts +1 -1
- package/src/synthesis/EspeakTTS.ts +0 -15
- package/src/synthesis/FliteTTS.ts +7 -8
- package/src/synthesis/GoogleCloudTTS.ts +3 -2
- package/src/synthesis/GoogleTranslateTTS.ts +5 -4
- package/src/synthesis/MicrosoftEdgeTTS.ts +47 -15
- package/src/synthesis/SapiTTS.ts +1 -1
- package/src/synthesis/StreamlabsPollyTTS.ts +1 -1
- package/src/synthesis/SvoxPicoTTS.ts +8 -7
- package/src/synthesis/VitsTTS.ts +2 -2
- package/src/tests/Test.ts +0 -30
- package/src/text-language-detection/FastTextLanguageDetection.ts +2 -2
- package/src/typings/Fillers.d.ts +2 -4
- package/src/typings/TypedArray.ts +5 -0
- package/src/utilities/BinaryArrayConversion.ts +51 -125
- package/src/utilities/BinaryUtilities.ts +138 -0
- package/src/utilities/Compression.ts +7 -6
- package/src/utilities/FileDownloader.ts +27 -52
- package/src/utilities/FileReader.ts +89 -0
- package/src/utilities/FileSystem.ts +215 -116
- package/src/utilities/FileWriter.ts +72 -0
- package/src/utilities/NpmUtilities.ts +23 -0
- package/src/utilities/PackageManager.ts +8 -5
- package/src/utilities/PathUtilities.ts +36 -7
- package/src/utilities/SignalChannel.ts +14 -7
- package/src/utilities/StringBuilder.ts +45 -0
- package/src/utilities/StringUtilities.ts +2 -0
- package/src/utilities/TarballMaker.ts +6 -7
- package/src/utilities/Timer.ts +4 -2
- package/src/utilities/Utilities.ts +80 -23
- package/src/utilities/VirtualFileReadStream.ts +5 -5
- package/src/utilities/WasmMemoryManager.ts +21 -5
- package/tsconfig.json +96 -0
- package/dist/utilities/DynamicUint8Array.d.ts +0 -9
- package/dist/utilities/DynamicUint8Array.js +0 -31
- package/dist/utilities/DynamicUint8Array.js.map +0 -1
- package/dist/utilities/LEB128.js.map +0 -1
- package/dist/utilities/LPVarInt.js.map +0 -1
- package/dist/utilities/Queue.js.map +0 -1
- package/dist/utilities/WindowedList.js.map +0 -1
- package/src/utilities/DynamicUint8Array.ts +0 -39
- /package/dist/{utilities → data-structures}/Queue.d.ts +0 -0
- /package/dist/{utilities → data-structures}/Queue.js +0 -0
- /package/dist/{utilities → data-structures}/WindowedList.d.ts +0 -0
- /package/dist/{utilities → data-structures}/WindowedList.js +0 -0
- /package/src/{utilities → data-structures}/Queue.ts +0 -0
- /package/src/{utilities → data-structures}/WindowedList.ts +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import { languageCodeToName } from '../utilities/Locale.js';
|
|
3
2
|
import { OpenPromise } from '../utilities/OpenPromise.js';
|
|
4
3
|
import { resolveModuleMainPath, roundToDigits } from '../utilities/Utilities.js';
|
|
4
|
+
import { getDirName, joinPath } from '../utilities/PathUtilities.js';
|
|
5
5
|
let fastTextLanguageDetectionModel;
|
|
6
6
|
export async function detectLanguage(text) {
|
|
7
7
|
const model = await loadLanguageDetectionModel();
|
|
@@ -28,7 +28,7 @@ async function loadLanguageDetectionModel() {
|
|
|
28
28
|
addOnPostRun(async () => {
|
|
29
29
|
const fastText = new FastText();
|
|
30
30
|
const moduleMainPath = await resolveModuleMainPath('@echogarden/fasttext-wasm');
|
|
31
|
-
const modelPath =
|
|
31
|
+
const modelPath = joinPath(getDirName(moduleMainPath), 'lid.176.ftz');
|
|
32
32
|
const model = await fastText.loadModel(modelPath);
|
|
33
33
|
fastTextLanguageDetectionModel = model;
|
|
34
34
|
resultPromise.resolve(model);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FastTextLanguageDetection.js","sourceRoot":"","sources":["../../src/text-language-detection/FastTextLanguageDetection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FastTextLanguageDetection.js","sourceRoot":"","sources":["../../src/text-language-detection/FastTextLanguageDetection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAA;AACzD,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAA;AAEhF,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AAEpE,IAAI,8BAAmC,CAAA;AAEvC,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAChD,MAAM,KAAK,GAAG,MAAM,0BAA0B,EAAE,CAAA;IAEhD,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAEtD,MAAM,WAAW,GAA6B,EAAE,CAAA;IAEhD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QACnD,MAAM,UAAU,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAA;QAC3C,MAAM,YAAY,GAAG,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;QAC/C,MAAM,WAAW,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;QAEnD,WAAW,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,YAAY;YACtB,YAAY,EAAE,kBAAkB,CAAC,YAAY,CAAC;YAC9C,WAAW;SACX,CAAC,CAAA;IACH,CAAC;IAED,OAAO,WAAW,CAAA;AACnB,CAAC;AAED,KAAK,UAAU,0BAA0B;IACxC,IAAI,8BAA8B,EAAE,CAAC;QACpC,OAAO,8BAA8B,CAAA;IACtC,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAA;IAE5E,MAAM,aAAa,GAAG,IAAI,WAAW,EAAO,CAAA;IAE5C,YAAY,CAAC,KAAK,IAAI,EAAE;QACvB,MAAM,QAAQ,GAAG,IAAI,QAAQ,EAAE,CAAA;QAE/B,MAAM,cAAc,GAAG,MAAM,qBAAqB,CAAC,2BAA2B,CAAC,CAAA;QAC/E,MAAM,SAAS,GAAG,QAAQ,CAAC,UAAU,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,CAAA;QAErE,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,CAAA;QAEjD,8BAA8B,GAAG,KAAK,CAAA;QACtC,aAAa,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,OAAO,aAAa,CAAC,OAAO,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TypedArray.js","sourceRoot":"","sources":["../../src/typings/TypedArray.ts"],"names":[],"mappings":""}
|
|
@@ -1,24 +1,14 @@
|
|
|
1
|
-
export declare function int8ToBuffer(int8s: Int8Array):
|
|
2
|
-
export declare function
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function bufferLEToInt32(buffer: Buffer): Int32Array;
|
|
14
|
-
export declare function bufferLEToInt32_Slow(buffer: Buffer): Int32Array;
|
|
15
|
-
export declare function float32ToBufferLE(float32s: Float32Array): Buffer;
|
|
16
|
-
export declare function float32ToBufferLE_Slow(float32s: Float32Array): Buffer;
|
|
17
|
-
export declare function bufferLEToFloat32(buffer: Buffer): Float32Array;
|
|
18
|
-
export declare function bufferLEToFloat32_Slow(buffer: Buffer): Float32Array;
|
|
19
|
-
export declare function float64ToBufferLE(float64s: Float64Array): Buffer;
|
|
20
|
-
export declare function float64ToBufferLE_Slow(float64s: Float64Array): Buffer;
|
|
21
|
-
export declare function bufferLEToFloat64(buffer: Buffer): Float64Array;
|
|
22
|
-
export declare function bufferLEToFloat64_Slow(buffer: Buffer): Float64Array;
|
|
1
|
+
export declare function int8ToBuffer(int8s: Int8Array): Uint8Array;
|
|
2
|
+
export declare function bufferToInt8(buffer: Uint8Array): Int8Array;
|
|
3
|
+
export declare function int16ToBufferLE(int16s: Int16Array): Uint8Array;
|
|
4
|
+
export declare function bufferLEToInt16(buffer: Uint8Array): Int16Array;
|
|
5
|
+
export declare function int24ToBufferLE(int24s: Int32Array): Uint8Array;
|
|
6
|
+
export declare function bufferLEToInt24(buffer: Uint8Array): Int32Array;
|
|
7
|
+
export declare function int32ToBufferLE(int32s: Int32Array): Uint8Array;
|
|
8
|
+
export declare function bufferLEToInt32(buffer: Uint8Array): Int32Array;
|
|
9
|
+
export declare function float32ToBufferLE(float32s: Float32Array): Uint8Array;
|
|
10
|
+
export declare function bufferLEToFloat32(buffer: Uint8Array): Float32Array;
|
|
11
|
+
export declare function float64ToBufferLE(float64s: Float64Array): Uint8Array;
|
|
12
|
+
export declare function bufferLEToFloat64(buffer: Uint8Array): Float64Array;
|
|
23
13
|
export declare function float64Tofloat32(float64s: Float64Array): Float32Array;
|
|
24
14
|
export declare function float32Tofloat64(float32s: Float32Array): Float64Array;
|
|
@@ -1,137 +1,87 @@
|
|
|
1
|
-
// Typed arrays to
|
|
1
|
+
// Typed arrays to Uint8Array buffers (little endian) conversions
|
|
2
2
|
//
|
|
3
|
-
// The
|
|
3
|
+
// The conversion methods (other than the methods for int8 and int24) would only work correctly
|
|
4
4
|
// on little-endian architectures, since they assume the byte order of the underlying architecture.
|
|
5
5
|
//
|
|
6
6
|
// Since Echogarden only supports little-endian architectures, this shouldn't matter.
|
|
7
7
|
// int8 <-> bufferLE
|
|
8
8
|
export function int8ToBuffer(int8s) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
export function int8ToBuffer_Slow(int8s) {
|
|
12
|
-
const buffer = Buffer.alloc(int8s.length);
|
|
13
|
-
for (let i = 0; i < int8s.length; i++) {
|
|
14
|
-
buffer[i] = int8s[i] + 128;
|
|
15
|
-
}
|
|
16
|
-
return buffer;
|
|
9
|
+
return new Uint8Array(int8s.buffer, int8s.byteOffset, int8s.byteLength);
|
|
17
10
|
}
|
|
18
11
|
export function bufferToInt8(buffer) {
|
|
19
12
|
return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
20
13
|
}
|
|
21
|
-
export function bufferToInt8_Slow(buffer) {
|
|
22
|
-
const result = new Int8Array(buffer.length);
|
|
23
|
-
for (let i = 0; i < result.length; i++) {
|
|
24
|
-
result[i] = buffer[i] - 128;
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
14
|
// int16 <-> bufferLE
|
|
29
15
|
export function int16ToBufferLE(int16s) {
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
export function int16ToBufferLE_Slow(int16s) {
|
|
33
|
-
const buffer = Buffer.alloc(int16s.length * 2);
|
|
34
|
-
for (let i = 0; i < int16s.length; i++) {
|
|
35
|
-
buffer.writeInt16LE(int16s[i], i * 2);
|
|
36
|
-
}
|
|
37
|
-
return buffer;
|
|
16
|
+
return new Uint8Array(int16s.buffer, int16s.byteOffset, int16s.byteLength);
|
|
38
17
|
}
|
|
39
18
|
export function bufferLEToInt16(buffer) {
|
|
40
19
|
return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2);
|
|
41
20
|
}
|
|
42
|
-
export function bufferLEToInt16_Slow(buffer) {
|
|
43
|
-
const result = new Int16Array(buffer.length / 2);
|
|
44
|
-
for (let i = 0; i < result.length; i++) {
|
|
45
|
-
result[i] = buffer.readInt16LE(i * 2);
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
21
|
// int24 <-> bufferLE (uses int32 for storage)
|
|
50
22
|
export function int24ToBufferLE(int24s) {
|
|
51
|
-
const buffer =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
23
|
+
const buffer = new Uint8Array(int24s.length * 3);
|
|
24
|
+
let readOffset = 0;
|
|
25
|
+
let writeOffset = 0;
|
|
26
|
+
while (readOffset < int24s.length) {
|
|
27
|
+
const signedValue = int24s[readOffset++];
|
|
28
|
+
let unsignedValue;
|
|
29
|
+
if (signedValue >= 0) {
|
|
30
|
+
unsignedValue = signedValue;
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
unsignedValue = signedValue + (2 ** 24);
|
|
34
|
+
}
|
|
35
|
+
buffer[writeOffset++] = (unsignedValue) & 0xff;
|
|
36
|
+
buffer[writeOffset++] = (unsignedValue >> 8) & 0xff;
|
|
37
|
+
buffer[writeOffset++] = (unsignedValue >> 16) & 0xff;
|
|
58
38
|
}
|
|
59
39
|
return buffer;
|
|
60
40
|
}
|
|
61
41
|
export function bufferLEToInt24(buffer) {
|
|
42
|
+
if (buffer.length % 3 !== 0) {
|
|
43
|
+
throw new Error(`Buffer has a length of ${buffer.length}, which is not a multiple of 3`);
|
|
44
|
+
}
|
|
62
45
|
const result = new Int32Array(buffer.length / 3);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
const
|
|
68
|
-
|
|
46
|
+
let readOffset = 0;
|
|
47
|
+
let writeOffset = 0;
|
|
48
|
+
while (writeOffset < result.length) {
|
|
49
|
+
const b0 = buffer[readOffset++];
|
|
50
|
+
const b1 = buffer[readOffset++];
|
|
51
|
+
const b2 = buffer[readOffset++];
|
|
52
|
+
const unsignedValue = (b0) | (b1 << 8) | (b2 << 16);
|
|
53
|
+
let signedValue;
|
|
54
|
+
if (unsignedValue < 2 ** 23) {
|
|
55
|
+
signedValue = unsignedValue;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
signedValue = unsignedValue - (2 ** 24);
|
|
59
|
+
}
|
|
60
|
+
result[writeOffset++] = signedValue;
|
|
69
61
|
}
|
|
70
62
|
return result;
|
|
71
63
|
}
|
|
72
64
|
// int32 <-> bufferLE
|
|
73
65
|
export function int32ToBufferLE(int32s) {
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
export function int32ToBufferLE_Slow(int32s) {
|
|
77
|
-
const buffer = Buffer.alloc(int32s.length * 4);
|
|
78
|
-
for (let i = 0; i < int32s.length; i++) {
|
|
79
|
-
buffer.writeInt32LE(int32s[i], i * 4);
|
|
80
|
-
}
|
|
81
|
-
return buffer;
|
|
66
|
+
return new Uint8Array(int32s.buffer, int32s.byteOffset, int32s.byteLength);
|
|
82
67
|
}
|
|
83
68
|
export function bufferLEToInt32(buffer) {
|
|
84
69
|
return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
|
|
85
70
|
}
|
|
86
|
-
export function bufferLEToInt32_Slow(buffer) {
|
|
87
|
-
const result = new Int32Array(buffer.length / 4);
|
|
88
|
-
for (let i = 0; i < result.length; i++) {
|
|
89
|
-
result[i] = buffer.readInt32LE(i * 4);
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
71
|
// float32 <-> bufferLE
|
|
94
72
|
export function float32ToBufferLE(float32s) {
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
export function float32ToBufferLE_Slow(float32s) {
|
|
98
|
-
const buffer = Buffer.alloc(float32s.length * 4);
|
|
99
|
-
for (let i = 0; i < float32s.length; i++) {
|
|
100
|
-
buffer.writeFloatLE(float32s[i], i * 4);
|
|
101
|
-
}
|
|
102
|
-
return buffer;
|
|
73
|
+
return new Uint8Array(float32s.buffer, float32s.byteOffset, float32s.byteLength);
|
|
103
74
|
}
|
|
104
75
|
export function bufferLEToFloat32(buffer) {
|
|
105
76
|
return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4);
|
|
106
77
|
}
|
|
107
|
-
export function bufferLEToFloat32_Slow(buffer) {
|
|
108
|
-
const result = new Float32Array(buffer.length / 4);
|
|
109
|
-
for (let i = 0; i < result.length; i++) {
|
|
110
|
-
result[i] = buffer.readFloatLE(i * 4);
|
|
111
|
-
}
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
78
|
// float64 <-> bufferLE
|
|
115
79
|
export function float64ToBufferLE(float64s) {
|
|
116
|
-
return
|
|
117
|
-
}
|
|
118
|
-
export function float64ToBufferLE_Slow(float64s) {
|
|
119
|
-
const buffer = Buffer.alloc(float64s.length * 8);
|
|
120
|
-
for (let i = 0; i < float64s.length; i++) {
|
|
121
|
-
buffer.writeDoubleLE(float64s[i], i * 8);
|
|
122
|
-
}
|
|
123
|
-
return buffer;
|
|
80
|
+
return new Uint8Array(float64s.buffer, float64s.byteOffset, float64s.byteLength);
|
|
124
81
|
}
|
|
125
82
|
export function bufferLEToFloat64(buffer) {
|
|
126
83
|
return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8);
|
|
127
84
|
}
|
|
128
|
-
export function bufferLEToFloat64_Slow(buffer) {
|
|
129
|
-
const result = new Float64Array(buffer.length / 8);
|
|
130
|
-
for (let i = 0; i < result.length; i++) {
|
|
131
|
-
result[i] = buffer.readDoubleLE(i * 8);
|
|
132
|
-
}
|
|
133
|
-
return result;
|
|
134
|
-
}
|
|
135
85
|
// float64 <-> float32
|
|
136
86
|
export function float64Tofloat32(float64s) {
|
|
137
87
|
return Float32Array.from(float64s);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BinaryArrayConversion.js","sourceRoot":"","sources":["../../src/utilities/BinaryArrayConversion.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"BinaryArrayConversion.js","sourceRoot":"","sources":["../../src/utilities/BinaryArrayConversion.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,+FAA+F;AAC/F,mGAAmG;AACnG,EAAE;AACF,qFAAqF;AAErF,oBAAoB;AACpB,MAAM,UAAU,YAAY,CAAC,KAAgB;IAC5C,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;AACxE,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,MAAkB;IAC9C,OAAO,IAAI,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAC1E,CAAC;AAED,qBAAqB;AACrB,MAAM,UAAU,eAAe,CAAC,MAAkB;IACjD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;AAC3E,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAkB;IACjD,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;AAC/E,CAAC;AAED,8CAA8C;AAC9C,MAAM,UAAU,eAAe,CAAC,MAAkB;IACjD,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IAEhD,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,WAAW,GAAG,CAAC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AU,EAAE,QAAQ,CAAC,UAAU,CAAC,CAAA;AACjF,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,MAAkB;IACnD,OAAO,IAAI,YAAY,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA;AACjF,CAAC;AAED,sBAAsB;AACtB,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,QAAsB;IACtD,OAAO,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare function readUint8(buffer: Uint8Array, offset: number): number;
|
|
2
|
+
export declare function writeUint8(buffer: Uint8Array, value: number, offset: number): void;
|
|
3
|
+
export declare function readUint16LE(buffer: Uint8Array, offset: number): number;
|
|
4
|
+
export declare function writeUint16LE(buffer: Uint8Array, value: number, offset: number): void;
|
|
5
|
+
export declare function readUint32LE(buffer: Uint8Array, offset: number): number;
|
|
6
|
+
export declare function writeUint32LE(buffer: Uint8Array, value: number, offset: number): void;
|
|
7
|
+
export declare function readInt8(buffer: Uint8Array, offset: number): number;
|
|
8
|
+
export declare function writeInt8(buffer: Uint8Array, value: number, offset: number): void;
|
|
9
|
+
export declare function readInt16LE(buffer: Uint8Array, offset: number): number;
|
|
10
|
+
export declare function writeInt16LE(buffer: Uint8Array, value: number, offset: number): void;
|
|
11
|
+
export declare function readInt32LE(buffer: Uint8Array, offset: number): number;
|
|
12
|
+
export declare function writeInt32LE(buffer: Uint8Array, value: number, offset: number): void;
|
|
13
|
+
export declare function writeAscii(buffer: Uint8Array, asciiString: string, writeStartOffset: number): void;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Unsigned operations
|
|
3
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
export function readUint8(buffer, offset) {
|
|
5
|
+
return buffer[offset];
|
|
6
|
+
}
|
|
7
|
+
export function writeUint8(buffer, value, offset) {
|
|
8
|
+
if (value < 0 || value > 255) {
|
|
9
|
+
throw new Error(`Value ${value} is outside the range of an 8-bit unsigned integer`);
|
|
10
|
+
}
|
|
11
|
+
buffer[offset] = value;
|
|
12
|
+
}
|
|
13
|
+
export function readUint16LE(buffer, offset) {
|
|
14
|
+
return (buffer[offset]) | (buffer[offset + 1] << 8);
|
|
15
|
+
}
|
|
16
|
+
export function writeUint16LE(buffer, value, offset) {
|
|
17
|
+
if (value < 0 || value > 65535) {
|
|
18
|
+
throw new Error(`Value ${value} is outside the range of a 16-bit unsigned integer`);
|
|
19
|
+
}
|
|
20
|
+
buffer[offset] = value & 0xff;
|
|
21
|
+
buffer[offset + 1] = (value >>> 8) & 0xff;
|
|
22
|
+
}
|
|
23
|
+
export function readUint32LE(buffer, offset) {
|
|
24
|
+
return readInt32LE(buffer, offset) >>> 0;
|
|
25
|
+
}
|
|
26
|
+
export function writeUint32LE(buffer, value, offset) {
|
|
27
|
+
if (value < 0 || value > 4294967295) {
|
|
28
|
+
throw new Error(`Value ${value} is outside the range of a 32-bit unsigned integer`);
|
|
29
|
+
}
|
|
30
|
+
buffer[offset] = value & 0xff;
|
|
31
|
+
buffer[offset + 1] = (value >>> 8) & 0xff;
|
|
32
|
+
buffer[offset + 2] = (value >>> 16) & 0xff;
|
|
33
|
+
buffer[offset + 3] = (value >>> 24) & 0xff;
|
|
34
|
+
}
|
|
35
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
36
|
+
// Signed operations
|
|
37
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
38
|
+
export function readInt8(buffer, offset) {
|
|
39
|
+
const unsignedValue = buffer[offset];
|
|
40
|
+
if (unsignedValue < 128) {
|
|
41
|
+
return unsignedValue;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return unsignedValue - 256;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function writeInt8(buffer, value, offset) {
|
|
48
|
+
if (value < -128 || value > 127) {
|
|
49
|
+
throw new Error(`Value ${value} is outside the range of an 8-bit signed integer`);
|
|
50
|
+
}
|
|
51
|
+
let unsignedValue;
|
|
52
|
+
if (value >= 0) {
|
|
53
|
+
unsignedValue = value;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
unsignedValue = value + 256;
|
|
57
|
+
}
|
|
58
|
+
buffer[offset] = unsignedValue;
|
|
59
|
+
}
|
|
60
|
+
export function readInt16LE(buffer, offset) {
|
|
61
|
+
const unsignedValue = readUint16LE(buffer, offset);
|
|
62
|
+
if (unsignedValue < 32768) {
|
|
63
|
+
return unsignedValue;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
return unsignedValue - 65536;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export function writeInt16LE(buffer, value, offset) {
|
|
70
|
+
if (value < -32768 || value > 32767) {
|
|
71
|
+
throw new Error(`Value ${value} is outside the range of a 16-bit signed integer`);
|
|
72
|
+
}
|
|
73
|
+
let unsignedValue;
|
|
74
|
+
if (value >= 0) {
|
|
75
|
+
unsignedValue = value;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
unsignedValue = value + 65536;
|
|
79
|
+
}
|
|
80
|
+
writeUint16LE(buffer, unsignedValue, offset);
|
|
81
|
+
}
|
|
82
|
+
export function readInt32LE(buffer, offset) {
|
|
83
|
+
const value = (buffer[offset]) |
|
|
84
|
+
(buffer[offset + 1] << 8) |
|
|
85
|
+
(buffer[offset + 2] << 16) |
|
|
86
|
+
(buffer[offset + 3] << 24);
|
|
87
|
+
return value;
|
|
88
|
+
}
|
|
89
|
+
export function writeInt32LE(buffer, value, offset) {
|
|
90
|
+
if (value < -2147483648 || value > 2147483647) {
|
|
91
|
+
throw new Error(`Value ${value} is outside the range of a 32-bit signed integer`);
|
|
92
|
+
}
|
|
93
|
+
buffer[offset] = value & 0xff;
|
|
94
|
+
buffer[offset + 1] = (value >> 8) & 0xff;
|
|
95
|
+
buffer[offset + 2] = (value >> 16) & 0xff;
|
|
96
|
+
buffer[offset + 3] = (value >> 24) & 0xff;
|
|
97
|
+
}
|
|
98
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
99
|
+
// Misc operations
|
|
100
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
101
|
+
export function writeAscii(buffer, asciiString, writeStartOffset) {
|
|
102
|
+
const writeEndOffset = Math.min(writeStartOffset + asciiString.length, buffer.length);
|
|
103
|
+
let readOffset = 0;
|
|
104
|
+
let writeOffset = writeStartOffset;
|
|
105
|
+
while (writeOffset < writeEndOffset) {
|
|
106
|
+
const charCode = asciiString.charCodeAt(readOffset++);
|
|
107
|
+
if (charCode >= 128) {
|
|
108
|
+
throw new Error(`Character '${asciiString[readOffset]}' (code: ${charCode}) can't be encoded as ASCII`);
|
|
109
|
+
}
|
|
110
|
+
buffer[writeOffset++] = charCode;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
//# sourceMappingURL=BinaryUtilities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BinaryUtilities.js","sourceRoot":"","sources":["../../src/utilities/BinaryUtilities.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,sBAAsB;AACtB,qFAAqF;AACrF,MAAM,UAAU,SAAS,CAAC,MAAkB,EAAE,MAAc;IAC3D,OAAO,MAAM,CAAC,MAAM,CAAC,CAAA;AACtB,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAkB,EAAE,KAAa,EAAE,MAAc;IAC3E,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,GAAG,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,SAAS,KAAK,oDAAoD,CAAC,CAAA;IACpF,CAAC;IAED,MAAM,CAAC,MAAM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;AAClB,qFAAqF;AACrF,MAAM,UAAU,UAAU,CAAC,MAAkB,EAAE,WAAmB,EAAE,gBAAwB;IAC3F,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,gBAAgB,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;IAErF,IAAI,UAAU,GAAG,CAAC,CAAA;IAClB,IAAI,WAAW,GAAG,gBAAgB,CAAA;IAElC,OAAO,WAAW,GAAG,cAAc,EAAE,CAAC;QACrC,MAAM,QAAQ,GAAG,WAAW,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,CAAA;QAErD,IAAI,QAAQ,IAAI,GAAG,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,cAAc,WAAW,CAAC,UAAU,CAAC,YAAY,QAAQ,6BAA6B,CAAC,CAAA;QACxG,CAAC;QAED,MAAM,CAAC,WAAW,EAAE,CAAC,GAAG,QAAQ,CAAA;IACjC,CAAC;AACF,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
1
|
import { Logger } from './Logger.js';
|
|
3
2
|
import { readdir, stat } from './FileSystem.js';
|
|
3
|
+
import { encodeUtf8 } from '../encodings/Utf8.js';
|
|
4
|
+
import { getBaseName, getDirName } from './PathUtilities.js';
|
|
4
5
|
export async function createTarball(filePath, outputFile, prefixPath = '') {
|
|
5
6
|
const pathStat = await stat(filePath);
|
|
6
7
|
if (pathStat.isDirectory()) {
|
|
@@ -12,14 +13,14 @@ export async function createTarball(filePath, outputFile, prefixPath = '') {
|
|
|
12
13
|
}
|
|
13
14
|
export async function createTarballForFile(filePath, outputFile, prefixPath = '') {
|
|
14
15
|
const logger = new Logger();
|
|
15
|
-
logger.start(`Creating ${prefixPath ||
|
|
16
|
+
logger.start(`Creating ${prefixPath || getBaseName(outputFile)}`);
|
|
16
17
|
const { create } = await import('tar');
|
|
17
18
|
const inputFileStat = await stat(filePath);
|
|
18
19
|
if (!inputFileStat.isFile()) {
|
|
19
20
|
throw new Error(`${filePath} is not a file`);
|
|
20
21
|
}
|
|
21
|
-
const filename =
|
|
22
|
-
const dirname =
|
|
22
|
+
const filename = getBaseName(filePath);
|
|
23
|
+
const dirname = getDirName(filePath);
|
|
23
24
|
await create({
|
|
24
25
|
gzip: { level: 9 },
|
|
25
26
|
file: outputFile,
|
|
@@ -37,7 +38,7 @@ export async function createTarballForFile(filePath, outputFile, prefixPath = ''
|
|
|
37
38
|
}
|
|
38
39
|
export async function createTarballForDir(inputDir, outputFile, prefixPath = '') {
|
|
39
40
|
const logger = new Logger();
|
|
40
|
-
logger.start(`Creating ${prefixPath ||
|
|
41
|
+
logger.start(`Creating ${prefixPath || getBaseName(outputFile)}`);
|
|
41
42
|
const { create } = await import('tar');
|
|
42
43
|
const inputDirStat = await stat(inputDir);
|
|
43
44
|
if (!inputDirStat.isDirectory()) {
|
|
@@ -71,7 +72,7 @@ export async function extractTarball(filepath, outputDir) {
|
|
|
71
72
|
export async function getDeflateCompressionMetricsForString(str) {
|
|
72
73
|
const zlib = await import('node:zlib');
|
|
73
74
|
const { promisify } = await import('node:util');
|
|
74
|
-
const originalStringBytes =
|
|
75
|
+
const originalStringBytes = encodeUtf8(str);
|
|
75
76
|
const deflateRaw = promisify(zlib.deflateRaw);
|
|
76
77
|
const compressedStringBytes = await deflateRaw(originalStringBytes);
|
|
77
78
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Compression.js","sourceRoot":"","sources":["../../src/utilities/Compression.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Compression.js","sourceRoot":"","sources":["../../src/utilities/Compression.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACjD,O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QAEjB,GAAG,IAAI,KAAK,CAAA;IACb,CAAC;IAED,OAAO,MAAM,CAAA;AACd,CAAC"}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { request } from 'gaxios';
|
|
2
2
|
import { getRandomHexString, writeToStderr } from './Utilities.js';
|
|
3
|
-
import { OpenPromise } from './OpenPromise.js';
|
|
4
3
|
import { Timer } from './Timer.js';
|
|
5
4
|
import { Logger } from './Logger.js';
|
|
6
|
-
import path from 'node:path';
|
|
7
5
|
import { extractTarball } from './Compression.js';
|
|
8
|
-
import {
|
|
6
|
+
import { move, remove, readdir, ensureDir } from './FileSystem.js';
|
|
9
7
|
import chalk from 'chalk';
|
|
10
8
|
import { logLevelGreaterOrEqualTo } from '../api/GlobalOptions.js';
|
|
9
|
+
import { FileWriter } from './FileWriter.js';
|
|
10
|
+
import { joinPath } from './PathUtilities.js';
|
|
11
11
|
export async function downloadAndExtractTarball(options, targetDir, baseTempPath, displayName = 'archive') {
|
|
12
12
|
const logger = new Logger();
|
|
13
13
|
const randomID = getRandomHexString(16).toLowerCase();
|
|
14
|
-
const tempTarballPath =
|
|
15
|
-
const tempDirPath =
|
|
14
|
+
const tempTarballPath = joinPath(baseTempPath, `/${randomID}.tarball`);
|
|
15
|
+
const tempDirPath = joinPath(baseTempPath, `/${randomID}`);
|
|
16
16
|
await ensureDir(tempDirPath);
|
|
17
17
|
logger.end();
|
|
18
18
|
await downloadFile(options, tempTarballPath, `${chalk.cyanBright('Downloading')} ${chalk.greenBright(displayName)}`);
|
|
@@ -21,8 +21,8 @@ export async function downloadAndExtractTarball(options, targetDir, baseTempPath
|
|
|
21
21
|
await extractTarball(tempTarballPath, tempDirPath);
|
|
22
22
|
await remove(tempTarballPath);
|
|
23
23
|
for (const filename of await readdir(tempDirPath)) {
|
|
24
|
-
const sourceFilePath =
|
|
25
|
-
const targetFilePath =
|
|
24
|
+
const sourceFilePath = joinPath(tempDirPath, filename);
|
|
25
|
+
const targetFilePath = joinPath(targetDir, filename);
|
|
26
26
|
await move(sourceFilePath, targetFilePath);
|
|
27
27
|
}
|
|
28
28
|
await remove(tempDirPath);
|
|
@@ -30,7 +30,6 @@ export async function downloadAndExtractTarball(options, targetDir, baseTempPath
|
|
|
30
30
|
}
|
|
31
31
|
export async function downloadFile(options, targetFilePath, prompt = 'Downloading') {
|
|
32
32
|
const write = logLevelGreaterOrEqualTo('info') ? writeToStderr : () => { };
|
|
33
|
-
const downloadPromise = new OpenPromise();
|
|
34
33
|
const timer = new Timer();
|
|
35
34
|
options.responseType = 'stream';
|
|
36
35
|
const response = await request(options);
|
|
@@ -101,51 +100,31 @@ export async function downloadFile(options, targetFilePath, prompt = 'Downloadin
|
|
|
101
100
|
}
|
|
102
101
|
}
|
|
103
102
|
}
|
|
103
|
+
const contentLengthString = response.headers['content-length'];
|
|
104
|
+
totalBytes = contentLengthString != undefined ? parseInt(contentLengthString) : undefined;
|
|
104
105
|
const partialFilePath = `${targetFilePath}.${getRandomHexString(16)}.partial`;
|
|
105
|
-
const
|
|
106
|
+
const fileWriter = new FileWriter(partialFilePath);
|
|
106
107
|
let statusInterval = setInterval(() => {
|
|
107
108
|
updateStatus();
|
|
108
109
|
}, statusUpdateInterval);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
totalBytes = contentLengthString != undefined ? parseInt(contentLengthString) : undefined;
|
|
113
|
-
const chunkLength = chunk.length;
|
|
114
|
-
fileWriteStream.write(chunk);
|
|
115
|
-
downloadedBytes += chunkLength;
|
|
116
|
-
if (downloadStarted == false) {
|
|
110
|
+
try {
|
|
111
|
+
for await (const chunk of response.data) {
|
|
112
|
+
if (downloadStarted === false) {
|
|
117
113
|
downloadStarted = true;
|
|
118
114
|
}
|
|
115
|
+
downloadedBytes += chunk.length;
|
|
116
|
+
await fileWriter.write(chunk);
|
|
119
117
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
await move(partialFilePath, targetFilePath);
|
|
132
|
-
downloadPromise.resolve();
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
clearInterval(statusInterval);
|
|
136
|
-
downloadPromise.reject(err);
|
|
137
|
-
}
|
|
138
|
-
});
|
|
139
|
-
response.data.on('error', async (err) => {
|
|
140
|
-
try {
|
|
141
|
-
clearInterval(statusInterval);
|
|
142
|
-
fileWriteStream.end();
|
|
143
|
-
await remove(partialFilePath);
|
|
144
|
-
}
|
|
145
|
-
finally {
|
|
146
|
-
downloadPromise.reject(err);
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
return downloadPromise.promise;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
clearInterval(statusInterval);
|
|
121
|
+
await fileWriter.dispose();
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
clearInterval(statusInterval);
|
|
125
|
+
updateStatus();
|
|
126
|
+
await fileWriter.dispose();
|
|
127
|
+
write('\n');
|
|
128
|
+
await move(partialFilePath, targetFilePath);
|
|
150
129
|
}
|
|
151
130
|
//# sourceMappingURL=FileDownloader.js.map
|