echogarden 1.8.7 → 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 +135 -49
- 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 -6
- 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 +1 -47
- 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 -16
- package/dist/utilities/FileSystem.js +170 -109
- 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 -5
- package/dist/utilities/Utilities.js +69 -33
- 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 -4
- 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 +155 -53
- 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 -8
- package/src/synthesis/VitsTTS.ts +2 -2
- package/src/tests/Test.ts +1 -60
- 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 +213 -120
- 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 +79 -45
- package/src/utilities/VirtualFileReadStream.ts +5 -5
- package/src/utilities/WasmMemoryManager.ts +20 -6
- 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,186 +1,112 @@
|
|
|
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
|
|
|
8
8
|
// int8 <-> bufferLE
|
|
9
9
|
export function int8ToBuffer(int8s: Int8Array) {
|
|
10
|
-
return
|
|
10
|
+
return new Uint8Array(int8s.buffer, int8s.byteOffset, int8s.byteLength)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export function
|
|
14
|
-
const buffer = Buffer.alloc(int8s.length)
|
|
15
|
-
|
|
16
|
-
for (let i = 0; i < int8s.length; i++) {
|
|
17
|
-
buffer[i] = int8s[i] + 128
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return buffer
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function bufferToInt8(buffer: Buffer) {
|
|
13
|
+
export function bufferToInt8(buffer: Uint8Array) {
|
|
24
14
|
return new Int8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
25
15
|
}
|
|
26
16
|
|
|
27
|
-
export function bufferToInt8_Slow(buffer: Buffer) {
|
|
28
|
-
const result = new Int8Array(buffer.length)
|
|
29
|
-
|
|
30
|
-
for (let i = 0; i < result.length; i++) {
|
|
31
|
-
result[i] = buffer[i] - 128
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return result
|
|
35
|
-
}
|
|
36
|
-
|
|
37
17
|
// int16 <-> bufferLE
|
|
38
18
|
export function int16ToBufferLE(int16s: Int16Array) {
|
|
39
|
-
return
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function int16ToBufferLE_Slow(int16s: Int16Array) {
|
|
43
|
-
const buffer = Buffer.alloc(int16s.length * 2)
|
|
44
|
-
|
|
45
|
-
for (let i = 0; i < int16s.length; i++) {
|
|
46
|
-
buffer.writeInt16LE(int16s[i], i * 2)
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return buffer
|
|
19
|
+
return new Uint8Array(int16s.buffer, int16s.byteOffset, int16s.byteLength)
|
|
50
20
|
}
|
|
51
21
|
|
|
52
|
-
export function bufferLEToInt16(buffer:
|
|
22
|
+
export function bufferLEToInt16(buffer: Uint8Array) {
|
|
53
23
|
return new Int16Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 2)
|
|
54
24
|
}
|
|
55
25
|
|
|
56
|
-
|
|
57
|
-
|
|
26
|
+
// int24 <-> bufferLE (uses int32 for storage)
|
|
27
|
+
export function int24ToBufferLE(int24s: Int32Array) {
|
|
28
|
+
const buffer = new Uint8Array(int24s.length * 3)
|
|
58
29
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
30
|
+
let readOffset = 0
|
|
31
|
+
let writeOffset = 0
|
|
62
32
|
|
|
63
|
-
|
|
64
|
-
|
|
33
|
+
while (readOffset < int24s.length) {
|
|
34
|
+
const signedValue = int24s[readOffset++]
|
|
65
35
|
|
|
66
|
-
|
|
67
|
-
export function int24ToBufferLE(int24s: Int32Array) {
|
|
68
|
-
const buffer = Buffer.alloc(int24s.length * 3)
|
|
36
|
+
let unsignedValue: number
|
|
69
37
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
38
|
+
if (signedValue >= 0) {
|
|
39
|
+
unsignedValue = signedValue
|
|
40
|
+
} else {
|
|
41
|
+
unsignedValue = signedValue + (2 ** 24)
|
|
42
|
+
}
|
|
73
43
|
|
|
74
|
-
buffer[
|
|
75
|
-
buffer[
|
|
76
|
-
buffer[
|
|
44
|
+
buffer[writeOffset++] = (unsignedValue) & 0xff
|
|
45
|
+
buffer[writeOffset++] = (unsignedValue >> 8) & 0xff
|
|
46
|
+
buffer[writeOffset++] = (unsignedValue >> 16) & 0xff
|
|
77
47
|
}
|
|
78
48
|
|
|
79
49
|
return buffer
|
|
80
50
|
}
|
|
81
51
|
|
|
82
|
-
export function bufferLEToInt24(buffer:
|
|
52
|
+
export function bufferLEToInt24(buffer: Uint8Array) {
|
|
53
|
+
if (buffer.length % 3 !== 0) {
|
|
54
|
+
throw new Error(`Buffer has a length of ${buffer.length}, which is not a multiple of 3`)
|
|
55
|
+
}
|
|
56
|
+
|
|
83
57
|
const result = new Int32Array(buffer.length / 3)
|
|
84
58
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const b1 = buffer[(i * 3) + 1]
|
|
88
|
-
const b2 = buffer[(i * 3) + 2]
|
|
59
|
+
let readOffset = 0
|
|
60
|
+
let writeOffset = 0
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
62
|
+
while (writeOffset < result.length) {
|
|
63
|
+
const b0 = buffer[readOffset++]
|
|
64
|
+
const b1 = buffer[readOffset++]
|
|
65
|
+
const b2 = buffer[readOffset++]
|
|
93
66
|
|
|
94
|
-
|
|
95
|
-
}
|
|
67
|
+
const unsignedValue = (b0) | (b1 << 8) | (b2 << 16)
|
|
96
68
|
|
|
97
|
-
|
|
98
|
-
export function int32ToBufferLE(int32s: Int32Array) {
|
|
99
|
-
return Buffer.copyBytesFrom(int32s)
|
|
100
|
-
}
|
|
69
|
+
let signedValue: number
|
|
101
70
|
|
|
102
|
-
|
|
103
|
-
|
|
71
|
+
if (unsignedValue < 2 ** 23) {
|
|
72
|
+
signedValue = unsignedValue
|
|
73
|
+
} else {
|
|
74
|
+
signedValue = unsignedValue - (2 ** 24)
|
|
75
|
+
}
|
|
104
76
|
|
|
105
|
-
|
|
106
|
-
buffer.writeInt32LE(int32s[i], i * 4)
|
|
77
|
+
result[writeOffset++] = signedValue
|
|
107
78
|
}
|
|
108
79
|
|
|
109
|
-
return
|
|
80
|
+
return result
|
|
110
81
|
}
|
|
111
82
|
|
|
112
|
-
|
|
113
|
-
|
|
83
|
+
// int32 <-> bufferLE
|
|
84
|
+
export function int32ToBufferLE(int32s: Int32Array) {
|
|
85
|
+
return new Uint8Array(int32s.buffer, int32s.byteOffset, int32s.byteLength)
|
|
114
86
|
}
|
|
115
87
|
|
|
116
|
-
export function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (let i = 0; i < result.length; i++) {
|
|
120
|
-
result[i] = buffer.readInt32LE(i * 4)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return result
|
|
88
|
+
export function bufferLEToInt32(buffer: Uint8Array) {
|
|
89
|
+
return new Int32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
|
|
124
90
|
}
|
|
125
91
|
|
|
126
92
|
// float32 <-> bufferLE
|
|
127
93
|
export function float32ToBufferLE(float32s: Float32Array) {
|
|
128
|
-
return
|
|
94
|
+
return new Uint8Array(float32s.buffer, float32s.byteOffset, float32s.byteLength)
|
|
129
95
|
}
|
|
130
96
|
|
|
131
|
-
export function
|
|
132
|
-
const buffer = Buffer.alloc(float32s.length * 4)
|
|
133
|
-
|
|
134
|
-
for (let i = 0; i < float32s.length; i++) {
|
|
135
|
-
buffer.writeFloatLE(float32s[i], i * 4)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return buffer
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export function bufferLEToFloat32(buffer: Buffer) {
|
|
97
|
+
export function bufferLEToFloat32(buffer: Uint8Array) {
|
|
142
98
|
return new Float32Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 4)
|
|
143
99
|
}
|
|
144
100
|
|
|
145
|
-
export function bufferLEToFloat32_Slow(buffer: Buffer) {
|
|
146
|
-
const result = new Float32Array(buffer.length / 4)
|
|
147
|
-
|
|
148
|
-
for (let i = 0; i < result.length; i++) {
|
|
149
|
-
result[i] = buffer.readFloatLE(i * 4)
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return result
|
|
153
|
-
}
|
|
154
|
-
|
|
155
101
|
// float64 <-> bufferLE
|
|
156
102
|
export function float64ToBufferLE(float64s: Float64Array) {
|
|
157
|
-
return
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
export function float64ToBufferLE_Slow(float64s: Float64Array) {
|
|
161
|
-
const buffer = Buffer.alloc(float64s.length * 8)
|
|
162
|
-
|
|
163
|
-
for (let i = 0; i < float64s.length; i++) {
|
|
164
|
-
buffer.writeDoubleLE(float64s[i], i * 8)
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return buffer
|
|
103
|
+
return new Uint8Array(float64s.buffer, float64s.byteOffset, float64s.byteLength)
|
|
168
104
|
}
|
|
169
105
|
|
|
170
|
-
export function bufferLEToFloat64(buffer:
|
|
106
|
+
export function bufferLEToFloat64(buffer: Uint8Array) {
|
|
171
107
|
return new Float64Array(buffer.buffer, buffer.byteOffset, buffer.byteLength / 8)
|
|
172
108
|
}
|
|
173
109
|
|
|
174
|
-
export function bufferLEToFloat64_Slow(buffer: Buffer) {
|
|
175
|
-
const result = new Float64Array(buffer.length / 8)
|
|
176
|
-
|
|
177
|
-
for (let i = 0; i < result.length; i++) {
|
|
178
|
-
result[i] = buffer.readDoubleLE(i * 8)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
return result
|
|
182
|
-
}
|
|
183
|
-
|
|
184
110
|
// float64 <-> float32
|
|
185
111
|
export function float64Tofloat32(float64s: Float64Array) {
|
|
186
112
|
return Float32Array.from(float64s)
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Unsigned operations
|
|
3
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
4
|
+
export function readUint8(buffer: Uint8Array, offset: number) {
|
|
5
|
+
return buffer[offset]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function writeUint8(buffer: Uint8Array, value: number, offset: number) {
|
|
9
|
+
if (value < 0 || value > 255) {
|
|
10
|
+
throw new Error(`Value ${value} is outside the range of an 8-bit unsigned integer`)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
buffer[offset] = value
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function readUint16LE(buffer: Uint8Array, offset: number) {
|
|
17
|
+
return (buffer[offset]) | (buffer[offset + 1] << 8)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function writeUint16LE(buffer: Uint8Array, value: number, offset: number) {
|
|
21
|
+
if (value < 0 || value > 65535) {
|
|
22
|
+
throw new Error(`Value ${value} is outside the range of a 16-bit unsigned integer`)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
buffer[offset] = value & 0xff
|
|
26
|
+
buffer[offset + 1] = (value >>> 8) & 0xff
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function readUint32LE(buffer: Uint8Array, offset: number) {
|
|
30
|
+
return readInt32LE(buffer, offset) >>> 0
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function writeUint32LE(buffer: Uint8Array, value: number, offset: number) {
|
|
34
|
+
if (value < 0 || value > 4294967295) {
|
|
35
|
+
throw new Error(`Value ${value} is outside the range of a 32-bit unsigned integer`)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
buffer[offset] = value & 0xff
|
|
39
|
+
buffer[offset + 1] = (value >>> 8) & 0xff
|
|
40
|
+
buffer[offset + 2] = (value >>> 16) & 0xff
|
|
41
|
+
buffer[offset + 3] = (value >>> 24) & 0xff
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
45
|
+
// Signed operations
|
|
46
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
47
|
+
export function readInt8(buffer: Uint8Array, offset: number) {
|
|
48
|
+
const unsignedValue = buffer[offset]
|
|
49
|
+
|
|
50
|
+
if (unsignedValue < 128) {
|
|
51
|
+
return unsignedValue
|
|
52
|
+
} else {
|
|
53
|
+
return unsignedValue - 256
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function writeInt8(buffer: Uint8Array, value: number, offset: number) {
|
|
58
|
+
if (value < -128 || value > 127) {
|
|
59
|
+
throw new Error(`Value ${value} is outside the range of an 8-bit signed integer`)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
let unsignedValue: number
|
|
63
|
+
|
|
64
|
+
if (value >= 0) {
|
|
65
|
+
unsignedValue = value
|
|
66
|
+
} else {
|
|
67
|
+
unsignedValue = value + 256
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
buffer[offset] = unsignedValue
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function readInt16LE(buffer: Uint8Array, offset: number) {
|
|
74
|
+
const unsignedValue = readUint16LE(buffer, offset)
|
|
75
|
+
|
|
76
|
+
if (unsignedValue < 32768) {
|
|
77
|
+
return unsignedValue
|
|
78
|
+
} else {
|
|
79
|
+
return unsignedValue - 65536
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function writeInt16LE(buffer: Uint8Array, value: number, offset: number) {
|
|
84
|
+
if (value < -32768 || value > 32767) {
|
|
85
|
+
throw new Error(`Value ${value} is outside the range of a 16-bit signed integer`)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
let unsignedValue: number
|
|
89
|
+
|
|
90
|
+
if (value >= 0) {
|
|
91
|
+
unsignedValue = value
|
|
92
|
+
} else {
|
|
93
|
+
unsignedValue = value + 65536
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
writeUint16LE(buffer, unsignedValue, offset)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export function readInt32LE(buffer: Uint8Array, offset: number) {
|
|
100
|
+
const value =
|
|
101
|
+
(buffer[offset]) |
|
|
102
|
+
(buffer[offset + 1] << 8) |
|
|
103
|
+
(buffer[offset + 2] << 16) |
|
|
104
|
+
(buffer[offset + 3] << 24)
|
|
105
|
+
|
|
106
|
+
return value
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function writeInt32LE(buffer: Uint8Array, value: number, offset: number) {
|
|
110
|
+
if (value < -2147483648 || value > 2147483647) {
|
|
111
|
+
throw new Error(`Value ${value} is outside the range of a 32-bit signed integer`)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
buffer[offset] = value & 0xff
|
|
115
|
+
buffer[offset + 1] = (value >> 8) & 0xff
|
|
116
|
+
buffer[offset + 2] = (value >> 16) & 0xff
|
|
117
|
+
buffer[offset + 3] = (value >> 24) & 0xff
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
121
|
+
// Misc operations
|
|
122
|
+
/////////////////////////////////////////////////////////////////////////////////////
|
|
123
|
+
export function writeAscii(buffer: Uint8Array, asciiString: string, writeStartOffset: number) {
|
|
124
|
+
const writeEndOffset = Math.min(writeStartOffset + asciiString.length, buffer.length)
|
|
125
|
+
|
|
126
|
+
let readOffset = 0
|
|
127
|
+
let writeOffset = writeStartOffset
|
|
128
|
+
|
|
129
|
+
while (writeOffset < writeEndOffset) {
|
|
130
|
+
const charCode = asciiString.charCodeAt(readOffset++)
|
|
131
|
+
|
|
132
|
+
if (charCode >= 128) {
|
|
133
|
+
throw new Error(`Character '${asciiString[readOffset]}' (code: ${charCode}) can't be encoded as ASCII`)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
buffer[writeOffset++] = charCode
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -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
|
|
|
5
6
|
export async function createTarball(filePath: string, outputFile: string, prefixPath = '') {
|
|
6
7
|
const pathStat = await stat(filePath)
|
|
@@ -15,7 +16,7 @@ export async function createTarball(filePath: string, outputFile: string, prefix
|
|
|
15
16
|
export async function createTarballForFile(filePath: string, outputFile: string, prefixPath = '') {
|
|
16
17
|
const logger = new Logger()
|
|
17
18
|
|
|
18
|
-
logger.start(`Creating ${prefixPath ||
|
|
19
|
+
logger.start(`Creating ${prefixPath || getBaseName(outputFile)}`)
|
|
19
20
|
|
|
20
21
|
const { create } = await import('tar')
|
|
21
22
|
|
|
@@ -25,8 +26,8 @@ export async function createTarballForFile(filePath: string, outputFile: string,
|
|
|
25
26
|
throw new Error(`${filePath} is not a file`)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
|
-
const filename =
|
|
29
|
-
const dirname =
|
|
29
|
+
const filename = getBaseName(filePath)
|
|
30
|
+
const dirname = getDirName(filePath)
|
|
30
31
|
|
|
31
32
|
await create({
|
|
32
33
|
gzip: { level: 9 },
|
|
@@ -51,7 +52,7 @@ export async function createTarballForFile(filePath: string, outputFile: string,
|
|
|
51
52
|
export async function createTarballForDir(inputDir: string, outputFile: string, prefixPath = '') {
|
|
52
53
|
const logger = new Logger()
|
|
53
54
|
|
|
54
|
-
logger.start(`Creating ${prefixPath ||
|
|
55
|
+
logger.start(`Creating ${prefixPath || getBaseName(outputFile)}`)
|
|
55
56
|
|
|
56
57
|
const { create } = await import('tar')
|
|
57
58
|
|
|
@@ -98,7 +99,7 @@ export async function getDeflateCompressionMetricsForString(str: string) {
|
|
|
98
99
|
const zlib = await import('node:zlib')
|
|
99
100
|
const { promisify } = await import('node:util')
|
|
100
101
|
|
|
101
|
-
const originalStringBytes =
|
|
102
|
+
const originalStringBytes = encodeUtf8(str)
|
|
102
103
|
|
|
103
104
|
const deflateRaw = promisify(zlib.deflateRaw)
|
|
104
105
|
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { GaxiosOptions, request } from 'gaxios'
|
|
2
2
|
import { Readable } from 'stream'
|
|
3
3
|
import { getRandomHexString, writeToStderr } from './Utilities.js'
|
|
4
|
-
import { OpenPromise } from './OpenPromise.js'
|
|
5
4
|
|
|
6
5
|
import { Timer } from './Timer.js'
|
|
7
6
|
import { Logger } from './Logger.js'
|
|
8
|
-
import path from 'node:path'
|
|
9
7
|
import { extractTarball } from './Compression.js'
|
|
10
|
-
import {
|
|
8
|
+
import { move, remove, readdir, ensureDir } from './FileSystem.js'
|
|
11
9
|
import chalk from 'chalk'
|
|
12
10
|
import { logLevelGreaterOrEqualTo } from '../api/GlobalOptions.js'
|
|
11
|
+
import { FileWriter } from './FileWriter.js'
|
|
12
|
+
import { joinPath } from './PathUtilities.js'
|
|
13
13
|
|
|
14
14
|
export async function downloadAndExtractTarball(options: GaxiosOptions, targetDir: string, baseTempPath: string, displayName = 'archive') {
|
|
15
15
|
const logger = new Logger()
|
|
16
16
|
|
|
17
17
|
const randomID = getRandomHexString(16).toLowerCase()
|
|
18
|
-
const tempTarballPath =
|
|
19
|
-
const tempDirPath =
|
|
18
|
+
const tempTarballPath = joinPath(baseTempPath, `/${randomID}.tarball`)
|
|
19
|
+
const tempDirPath = joinPath(baseTempPath, `/${randomID}`)
|
|
20
20
|
await ensureDir(tempDirPath)
|
|
21
21
|
|
|
22
22
|
logger.end()
|
|
@@ -32,8 +32,8 @@ export async function downloadAndExtractTarball(options: GaxiosOptions, targetDi
|
|
|
32
32
|
await remove(tempTarballPath)
|
|
33
33
|
|
|
34
34
|
for (const filename of await readdir(tempDirPath)) {
|
|
35
|
-
const sourceFilePath =
|
|
36
|
-
const targetFilePath =
|
|
35
|
+
const sourceFilePath = joinPath(tempDirPath, filename)
|
|
36
|
+
const targetFilePath = joinPath(targetDir, filename)
|
|
37
37
|
|
|
38
38
|
await move(sourceFilePath, targetFilePath)
|
|
39
39
|
}
|
|
@@ -46,8 +46,6 @@ export async function downloadAndExtractTarball(options: GaxiosOptions, targetDi
|
|
|
46
46
|
export async function downloadFile(options: GaxiosOptions, targetFilePath: string, prompt = 'Downloading') {
|
|
47
47
|
const write = logLevelGreaterOrEqualTo('info') ? writeToStderr : () => {}
|
|
48
48
|
|
|
49
|
-
const downloadPromise = new OpenPromise<void>()
|
|
50
|
-
|
|
51
49
|
const timer = new Timer()
|
|
52
50
|
|
|
53
51
|
options.responseType = 'stream'
|
|
@@ -143,63 +141,40 @@ export async function downloadFile(options: GaxiosOptions, targetFilePath: strin
|
|
|
143
141
|
}
|
|
144
142
|
}
|
|
145
143
|
|
|
144
|
+
const contentLengthString = response.headers['content-length']
|
|
145
|
+
totalBytes = contentLengthString != undefined ? parseInt(contentLengthString) : undefined
|
|
146
|
+
|
|
146
147
|
const partialFilePath = `${targetFilePath}.${getRandomHexString(16)}.partial`
|
|
147
|
-
const
|
|
148
|
+
const fileWriter = new FileWriter(partialFilePath)
|
|
148
149
|
|
|
149
150
|
let statusInterval = setInterval(() => {
|
|
150
151
|
updateStatus()
|
|
151
152
|
}, statusUpdateInterval)
|
|
152
153
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
totalBytes = contentLengthString != undefined ? parseInt(contentLengthString) : undefined
|
|
158
|
-
|
|
159
|
-
const chunkLength = chunk.length
|
|
160
|
-
|
|
161
|
-
fileWriteStream.write(chunk)
|
|
162
|
-
|
|
163
|
-
downloadedBytes += chunkLength
|
|
164
|
-
|
|
165
|
-
if (downloadStarted == false) {
|
|
154
|
+
try {
|
|
155
|
+
for await (const chunk of response.data) {
|
|
156
|
+
if (downloadStarted === false) {
|
|
166
157
|
downloadStarted = true
|
|
167
158
|
}
|
|
168
|
-
} catch (err) {
|
|
169
|
-
clearInterval(statusInterval)
|
|
170
159
|
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
})
|
|
174
|
-
|
|
175
|
-
response.data.on('end', async () => {
|
|
176
|
-
try {
|
|
177
|
-
clearInterval(statusInterval)
|
|
178
|
-
updateStatus()
|
|
160
|
+
downloadedBytes += chunk.length
|
|
179
161
|
|
|
180
|
-
|
|
162
|
+
await fileWriter.write(chunk)
|
|
163
|
+
}
|
|
164
|
+
} catch (e) {
|
|
165
|
+
clearInterval(statusInterval)
|
|
181
166
|
|
|
182
|
-
|
|
167
|
+
await fileWriter.dispose()
|
|
183
168
|
|
|
184
|
-
|
|
169
|
+
throw e
|
|
170
|
+
}
|
|
185
171
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
clearInterval(statusInterval)
|
|
189
|
-
downloadPromise.reject(err)
|
|
190
|
-
}
|
|
191
|
-
})
|
|
172
|
+
clearInterval(statusInterval)
|
|
173
|
+
updateStatus()
|
|
192
174
|
|
|
193
|
-
|
|
194
|
-
try {
|
|
195
|
-
clearInterval(statusInterval)
|
|
175
|
+
await fileWriter.dispose()
|
|
196
176
|
|
|
197
|
-
|
|
198
|
-
await remove(partialFilePath)
|
|
199
|
-
} finally {
|
|
200
|
-
downloadPromise.reject(err)
|
|
201
|
-
}
|
|
202
|
-
})
|
|
177
|
+
write('\n')
|
|
203
178
|
|
|
204
|
-
|
|
179
|
+
await move(partialFilePath, targetFilePath)
|
|
205
180
|
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { open, close, read } from "./FileSystem.js"
|
|
2
|
+
|
|
3
|
+
export class FileReader {
|
|
4
|
+
private fileHandle?: number
|
|
5
|
+
private finished = false
|
|
6
|
+
private disposed = false
|
|
7
|
+
private readOffset = 0
|
|
8
|
+
|
|
9
|
+
constructor(public readonly filePath: string) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async readChunk(buffer: Uint8Array): Promise<Uint8Array> {
|
|
13
|
+
if (this.isDisposed) {
|
|
14
|
+
throw new Error(`FileReader has been disposed`)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
await this.openIfNeeded()
|
|
18
|
+
|
|
19
|
+
let bufferWriteOffset = 0
|
|
20
|
+
|
|
21
|
+
while (bufferWriteOffset < buffer.length) {
|
|
22
|
+
const remainingSizeInBuffer = buffer.length - bufferWriteOffset
|
|
23
|
+
|
|
24
|
+
let bytesRead: number
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
({ bytesRead } = await read(this.fileHandle!, buffer, bufferWriteOffset, remainingSizeInBuffer, this.readOffset))
|
|
28
|
+
} catch (e) {
|
|
29
|
+
await this.dispose()
|
|
30
|
+
|
|
31
|
+
throw e
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (bytesRead === 0) {
|
|
35
|
+
this.finished = true
|
|
36
|
+
|
|
37
|
+
await this.dispose()
|
|
38
|
+
|
|
39
|
+
break
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
bufferWriteOffset += bytesRead
|
|
43
|
+
this.readOffset += bytesRead
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return buffer.subarray(0, bufferWriteOffset)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private async openIfNeeded() {
|
|
50
|
+
if (this.isDisposed) {
|
|
51
|
+
throw new Error(`FileWriter has been disposed`)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (this.isOpened) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.fileHandle = await open(this.filePath, 'r')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async dispose() {
|
|
62
|
+
if (this.isDisposed) {
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (this.isOpened) {
|
|
67
|
+
try {
|
|
68
|
+
await close(this.fileHandle!)
|
|
69
|
+
} catch (e) {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
this.disposed = true
|
|
74
|
+
this.readOffset = 0
|
|
75
|
+
this.fileHandle = undefined
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
get isOpened() {
|
|
79
|
+
return this.fileHandle !== undefined
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get isDisposed() {
|
|
83
|
+
return this.disposed
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get isFinished() {
|
|
87
|
+
return this.finished
|
|
88
|
+
}
|
|
89
|
+
}
|