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,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
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FileDownloader.js","sourceRoot":"","sources":["../../src/utilities/FileDownloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAE,MAAM,QAAQ,CAAA;AAE/C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"FileDownloader.js","sourceRoot":"","sources":["../../src/utilities/FileDownloader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,OAAO,EAAE,MAAM,QAAQ,CAAA;AAE/C,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAElE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAClE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAE7C,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,OAAsB,EAAE,SAAiB,EAAE,YAAoB,EAAE,WAAW,GAAG,SAAS;IACvI,MAAM,MAAM,GAAG,IAAI,MAAM,EAAE,CAAA;IAE3B,MAAM,QAAQ,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC,WAAW,E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eAAe,GAAG,IAAI,CAAA;YACvB,CAAC;YAED,eAAe,IAAI,KAAK,CAAC,MAAM,CAAA;YAE/B,MAAM,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAC9B,CAAC;IACF,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACZ,aAAa,CAAC,cAAc,CAAC,CAAA;QAE7B,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;QAE1B,MAAM,CAAC,CAAA;IACR,CAAC;IAED,aAAa,CAAC,cAAc,CAAC,CAAA;IAC7B,YAAY,EAAE,CAAA;IAEd,MAAM,UAAU,CAAC,OAAO,EAAE,CAAA;IAE1B,KAAK,CAAC,IAAI,CAAC,CAAA;IAEX,MAAM,IAAI,CAAC,eAAe,EAAE,cAAc,CAAC,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class FileReader {
|
|
2
|
+
readonly filePath: string;
|
|
3
|
+
private fileHandle?;
|
|
4
|
+
private finished;
|
|
5
|
+
private disposed;
|
|
6
|
+
private readOffset;
|
|
7
|
+
constructor(filePath: string);
|
|
8
|
+
readChunk(buffer: Uint8Array): Promise<Uint8Array>;
|
|
9
|
+
private openIfNeeded;
|
|
10
|
+
dispose(): Promise<void>;
|
|
11
|
+
get isOpened(): boolean;
|
|
12
|
+
get isDisposed(): boolean;
|
|
13
|
+
get isFinished(): boolean;
|
|
14
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { open, close, read } from "./FileSystem.js";
|
|
2
|
+
export class FileReader {
|
|
3
|
+
filePath;
|
|
4
|
+
fileHandle;
|
|
5
|
+
finished = false;
|
|
6
|
+
disposed = false;
|
|
7
|
+
readOffset = 0;
|
|
8
|
+
constructor(filePath) {
|
|
9
|
+
this.filePath = filePath;
|
|
10
|
+
}
|
|
11
|
+
async readChunk(buffer) {
|
|
12
|
+
if (this.isDisposed) {
|
|
13
|
+
throw new Error(`FileReader has been disposed`);
|
|
14
|
+
}
|
|
15
|
+
await this.openIfNeeded();
|
|
16
|
+
let bufferWriteOffset = 0;
|
|
17
|
+
while (bufferWriteOffset < buffer.length) {
|
|
18
|
+
const remainingSizeInBuffer = buffer.length - bufferWriteOffset;
|
|
19
|
+
let bytesRead;
|
|
20
|
+
try {
|
|
21
|
+
({ bytesRead } = await read(this.fileHandle, buffer, bufferWriteOffset, remainingSizeInBuffer, this.readOffset));
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
await this.dispose();
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
if (bytesRead === 0) {
|
|
28
|
+
this.finished = true;
|
|
29
|
+
await this.dispose();
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
bufferWriteOffset += bytesRead;
|
|
33
|
+
this.readOffset += bytesRead;
|
|
34
|
+
}
|
|
35
|
+
return buffer.subarray(0, bufferWriteOffset);
|
|
36
|
+
}
|
|
37
|
+
async openIfNeeded() {
|
|
38
|
+
if (this.isDisposed) {
|
|
39
|
+
throw new Error(`FileWriter has been disposed`);
|
|
40
|
+
}
|
|
41
|
+
if (this.isOpened) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
this.fileHandle = await open(this.filePath, 'r');
|
|
45
|
+
}
|
|
46
|
+
async dispose() {
|
|
47
|
+
if (this.isDisposed) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (this.isOpened) {
|
|
51
|
+
try {
|
|
52
|
+
await close(this.fileHandle);
|
|
53
|
+
}
|
|
54
|
+
catch (e) {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
this.disposed = true;
|
|
58
|
+
this.readOffset = 0;
|
|
59
|
+
this.fileHandle = undefined;
|
|
60
|
+
}
|
|
61
|
+
get isOpened() {
|
|
62
|
+
return this.fileHandle !== undefined;
|
|
63
|
+
}
|
|
64
|
+
get isDisposed() {
|
|
65
|
+
return this.disposed;
|
|
66
|
+
}
|
|
67
|
+
get isFinished() {
|
|
68
|
+
return this.finished;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=FileReader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FileReader.js","sourceRoot":"","sources":["../../src/utilities/FileReader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAEnD,MAAM,OAAO,UAAU;IAMM;IALpB,UAAU,CAAS;IACnB,QAAQ,GAAG,KAAK,CAAA;IAChB,QAAQ,GAAG,KAAK,CAAA;IAChB,UAAU,GAAG,CAAC,CAAA;IAEtB,YAA4B,QAAgB;QAAhB,aAAQ,GAAR,QAAQ,CAAQ;IAC5C,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAkB;QACjC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;QAChD,CAAC;QAED,MAAM,IAAI,CAAC,YAAY,EAAE,CAAA;QAEzB,IAAI,iBAAiB,GAAG,CAAC,CAAA;QAEzB,OAAO,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC;YAC1C,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,GAAG,iBAAiB,CAAA;YAE/D,IAAI,SAAiB,CAAA;YAErB,IAAI,CAAC;gBACJ,CAAC,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAW,EAAE,MAAM,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,CAAA;YAClH,CAAC;YAAC,OAAO,CAAC,EAAE,CAAC;gBACZ,MAAM,IAAI,CAAC,OAAO,EAAE,CAAA;gBAEpB,MAAM,CAAC,CAAA;YACR,CAAC;YAED,IAAI,SAAS,KAAK,CAAC,EAAE,CAAC;gBACrB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAA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
|
import gracefulFS from 'graceful-fs';
|
|
3
|
-
export declare const readFile: typeof gracefulFS.readFile.__promisify__;
|
|
4
|
-
export declare const readdir: typeof gracefulFS.readdir.__promisify__;
|
|
5
|
-
export declare const stat: typeof gracefulFS.stat.__promisify__;
|
|
6
3
|
export declare const open: typeof gracefulFS.open.__promisify__;
|
|
7
4
|
export declare const close: typeof gracefulFS.close.__promisify__;
|
|
5
|
+
export declare const read: typeof gracefulFS.read.__promisify__;
|
|
6
|
+
export declare const write: typeof gracefulFS.write.__promisify__;
|
|
7
|
+
export declare const existsSync: typeof gracefulFS.existsSync;
|
|
8
|
+
export declare const stat: typeof gracefulFS.stat.__promisify__;
|
|
8
9
|
export declare const chmod: typeof gracefulFS.chmod.__promisify__;
|
|
9
|
-
export declare const copyFile: typeof gracefulFS.copyFile.__promisify__;
|
|
10
10
|
export declare const access: typeof gracefulFS.access.__promisify__;
|
|
11
|
-
export declare const
|
|
12
|
-
export declare const
|
|
13
|
-
export declare const existsSync: typeof gracefulFS.existsSync;
|
|
11
|
+
export declare const readdir: typeof gracefulFS.readdir.__promisify__;
|
|
12
|
+
export declare const copyFile: typeof gracefulFS.copyFile.__promisify__;
|
|
14
13
|
export declare const remove: typeof fsExtra.remove;
|
|
15
14
|
export declare const copy: typeof fsExtra.copy;
|
|
16
|
-
export declare function
|
|
17
|
-
export declare function
|
|
18
|
-
export declare function computeFileSha256Hex(filePath: string): Promise<string>;
|
|
15
|
+
export declare function readFileAsBinary(filePath: string): Promise<Uint8Array>;
|
|
16
|
+
export declare function readFileAsUtf8(filePath: string): Promise<string>;
|
|
19
17
|
export declare function readAndParseJsonFile(jsonFilePath: string, useJson5?: boolean): Promise<any>;
|
|
20
|
-
export declare function writeFile(filePath: string,
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
18
|
+
export declare function writeFile(filePath: string, content: Uint8Array | string): Promise<void>;
|
|
19
|
+
export declare function writeBinaryFile(filePath: string, content: Uint8Array): Promise<void>;
|
|
20
|
+
export declare function writeUtf8File(filePath: string, content: string): Promise<void>;
|
|
21
|
+
export declare function writeJsonFile(filePath: string, content: any, useJson5?: boolean): Promise<void>;
|
|
22
|
+
export declare function writeFileSafe(filePath: string, content: Uint8Array | string): Promise<void>;
|
|
24
23
|
export declare function ensureDir(dirPath: string): Promise<void>;
|
|
24
|
+
export declare function testDirectoryIsWritable(dir: string): Promise<boolean>;
|
|
25
|
+
export declare function readDirRecursive(dir: string, pathFilter?: (filePath: string) => boolean): Promise<string[]>;
|
|
26
|
+
export declare function getAppDataDir(appName: string): string;
|
|
25
27
|
export declare function move(source: string, dest: string): Promise<void>;
|
|
26
28
|
export declare function existsAndIsWritable(targetPath: string): Promise<boolean>;
|
|
27
|
-
export declare function
|
|
28
|
-
export declare function
|
|
29
|
+
export declare function chmodRecursive(rootPath: string, newMode: number): Promise<void>;
|
|
30
|
+
export declare function isFileIsUpToDate(filePath: string, maxTimeDifferenceSeconds: number): Promise<boolean>;
|
|
31
|
+
export declare function computeFileSha256Hex(filePath: string): Promise<string>;
|
|
@@ -1,34 +1,147 @@
|
|
|
1
1
|
import * as fsExtra from 'fs-extra/esm';
|
|
2
2
|
import gracefulFS from 'graceful-fs';
|
|
3
3
|
import * as os from 'node:os';
|
|
4
|
-
import path from 'node:path';
|
|
5
4
|
import { promisify } from 'node:util';
|
|
6
|
-
import {
|
|
7
|
-
import { getRandomHexString } from './Utilities.js';
|
|
5
|
+
import { getRandomHexString, parseJson, stringifyAndFormatJson } from './Utilities.js';
|
|
8
6
|
import { appName } from '../api/Common.js';
|
|
9
|
-
import { getAppTempDir } from './PathUtilities.js';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export const stat = promisify(gracefulFS.stat);
|
|
7
|
+
import { getAppTempDir, getDirName, joinPath, normalizePath, parsePath } from './PathUtilities.js';
|
|
8
|
+
import { createDynamicUint8Array } from '../data-structures/DynamicTypedArray.js';
|
|
9
|
+
import { ChunkedUtf8Decoder } from '../encodings/Utf8.js';
|
|
10
|
+
import { FileWriter } from './FileWriter.js';
|
|
11
|
+
import { FileReader } from './FileReader.js';
|
|
15
12
|
export const open = promisify(gracefulFS.open);
|
|
16
13
|
export const close = promisify(gracefulFS.close);
|
|
14
|
+
export const read = promisify(gracefulFS.read);
|
|
15
|
+
export const write = promisify(gracefulFS.write);
|
|
16
|
+
export const existsSync = gracefulFS.existsSync;
|
|
17
|
+
export const stat = promisify(gracefulFS.stat);
|
|
17
18
|
export const chmod = promisify(gracefulFS.chmod);
|
|
18
|
-
export const copyFile = promisify(gracefulFS.copyFile);
|
|
19
19
|
export const access = promisify(gracefulFS.access);
|
|
20
|
-
export const
|
|
21
|
-
export const
|
|
22
|
-
export const existsSync = gracefulFS.existsSync;
|
|
20
|
+
export const readdir = promisify(gracefulFS.readdir);
|
|
21
|
+
export const copyFile = promisify(gracefulFS.copyFile);
|
|
23
22
|
export const remove = fsExtra.remove;
|
|
24
23
|
export const copy = fsExtra.copy;
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
25
|
+
// File read operations
|
|
26
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
27
|
+
export async function readFileAsBinary(filePath) {
|
|
28
|
+
const chunkSize = 2 ** 20;
|
|
29
|
+
const fileInfo = await stat(filePath);
|
|
30
|
+
const fileSize = fileInfo.size;
|
|
31
|
+
const fileReader = new FileReader(filePath);
|
|
32
|
+
const buffer = new Uint8Array(chunkSize);
|
|
33
|
+
const result = createDynamicUint8Array(fileSize);
|
|
34
|
+
while (!fileReader.isFinished) {
|
|
35
|
+
const chunk = await fileReader.readChunk(buffer);
|
|
36
|
+
result.addArray(chunk);
|
|
37
|
+
}
|
|
38
|
+
return result.toTypedArray();
|
|
39
|
+
}
|
|
40
|
+
export async function readFileAsUtf8(filePath) {
|
|
41
|
+
const chunkSize = 2 ** 20;
|
|
42
|
+
const fileReader = new FileReader(filePath);
|
|
43
|
+
const buffer = new Uint8Array(chunkSize);
|
|
44
|
+
const result = new ChunkedUtf8Decoder();
|
|
45
|
+
while (!fileReader.isFinished) {
|
|
46
|
+
const chunk = await fileReader.readChunk(buffer);
|
|
47
|
+
result.writeChunk(chunk);
|
|
48
|
+
}
|
|
49
|
+
return result.toString();
|
|
50
|
+
}
|
|
51
|
+
export async function readAndParseJsonFile(jsonFilePath, useJson5 = false) {
|
|
52
|
+
const textContent = await readFileAsUtf8(jsonFilePath);
|
|
53
|
+
return parseJson(textContent, useJson5);
|
|
54
|
+
}
|
|
55
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
56
|
+
// File write operations
|
|
57
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
58
|
+
export async function writeFile(filePath, content) {
|
|
59
|
+
if (content instanceof Uint8Array) {
|
|
60
|
+
return writeBinaryFile(filePath, content);
|
|
61
|
+
}
|
|
62
|
+
else if (typeof content === 'string') {
|
|
63
|
+
return writeUtf8File(filePath, content);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
throw new Error(`Content can only be a Uint8Array or string`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export async function writeBinaryFile(filePath, content) {
|
|
70
|
+
const maxChunkSize = 2 ** 20;
|
|
71
|
+
const fileDir = getDirName(filePath);
|
|
72
|
+
await ensureDir(fileDir);
|
|
73
|
+
const fileWriter = new FileWriter(filePath);
|
|
74
|
+
let readOffset = 0;
|
|
75
|
+
while (true) {
|
|
76
|
+
const chunk = content.subarray(readOffset, readOffset + maxChunkSize);
|
|
77
|
+
if (chunk.length === 0) {
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
await fileWriter.write(chunk);
|
|
81
|
+
readOffset += chunk.length;
|
|
82
|
+
}
|
|
83
|
+
await fileWriter.dispose();
|
|
84
|
+
}
|
|
85
|
+
export async function writeUtf8File(filePath, content) {
|
|
86
|
+
const maxChunkSize = 2 ** 20;
|
|
87
|
+
const fileDir = getDirName(filePath);
|
|
88
|
+
await ensureDir(fileDir);
|
|
89
|
+
const fileWriter = new FileWriter(filePath);
|
|
90
|
+
const textEncoder = new TextEncoder();
|
|
91
|
+
let readOffset = 0;
|
|
92
|
+
while (true) {
|
|
93
|
+
const stringChunk = content.substring(readOffset, readOffset + maxChunkSize);
|
|
94
|
+
if (stringChunk.length === 0) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
const chunk = textEncoder.encode(stringChunk);
|
|
98
|
+
await fileWriter.write(chunk);
|
|
99
|
+
readOffset += stringChunk.length;
|
|
100
|
+
}
|
|
101
|
+
await fileWriter.dispose();
|
|
102
|
+
}
|
|
103
|
+
export async function writeJsonFile(filePath, content, useJson5 = false) {
|
|
104
|
+
const textContent = await stringifyAndFormatJson(content, useJson5);
|
|
105
|
+
await writeUtf8File(filePath, textContent);
|
|
106
|
+
}
|
|
107
|
+
export async function writeFileSafe(filePath, content) {
|
|
108
|
+
const tempDir = getAppTempDir(appName);
|
|
109
|
+
const tempFilePath = joinPath(tempDir, `${getRandomHexString(16)}.partial`);
|
|
110
|
+
await writeFile(tempFilePath, content);
|
|
111
|
+
await move(tempFilePath, filePath);
|
|
112
|
+
}
|
|
113
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
114
|
+
// Directory operations
|
|
115
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
116
|
+
export async function ensureDir(dirPath) {
|
|
117
|
+
dirPath = normalizePath(dirPath);
|
|
118
|
+
if (existsSync(dirPath)) {
|
|
119
|
+
const dirStats = await stat(dirPath);
|
|
120
|
+
if (!dirStats.isDirectory()) {
|
|
121
|
+
throw new Error(`The path '${dirPath}' exists but is not a directory.`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
return fsExtra.ensureDir(dirPath);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
export async function testDirectoryIsWritable(dir) {
|
|
129
|
+
const testFileName = joinPath(dir, getRandomHexString(16));
|
|
130
|
+
try {
|
|
131
|
+
await fsExtra.createFile(testFileName);
|
|
132
|
+
await remove(testFileName);
|
|
133
|
+
}
|
|
134
|
+
catch (e) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
export async function readDirRecursive(dir, pathFilter) {
|
|
27
140
|
if (!(await stat(dir)).isDirectory()) {
|
|
28
141
|
throw new Error(`'${dir}' is not a directory`);
|
|
29
142
|
}
|
|
30
143
|
const filenamesInDir = await readdir(dir);
|
|
31
|
-
const filesInDir = filenamesInDir.map(filename =>
|
|
144
|
+
const filesInDir = filenamesInDir.map(filename => joinPath(dir, filename));
|
|
32
145
|
const result = [];
|
|
33
146
|
const subDirectories = [];
|
|
34
147
|
for (const filePath of filesInDir) {
|
|
@@ -36,100 +149,42 @@ export async function readDirRecursive(dir, fileFilter) {
|
|
|
36
149
|
subDirectories.push(filePath);
|
|
37
150
|
}
|
|
38
151
|
else {
|
|
39
|
-
if (
|
|
152
|
+
if (pathFilter && !pathFilter(filePath)) {
|
|
40
153
|
continue;
|
|
41
154
|
}
|
|
42
155
|
result.push(filePath);
|
|
43
156
|
}
|
|
44
157
|
}
|
|
45
158
|
for (const subDirectory of subDirectories) {
|
|
46
|
-
const filesInSubdirectory = await readDirRecursive(subDirectory,
|
|
159
|
+
const filesInSubdirectory = await readDirRecursive(subDirectory, pathFilter);
|
|
47
160
|
result.push(...filesInSubdirectory);
|
|
48
161
|
}
|
|
49
162
|
return result;
|
|
50
163
|
}
|
|
51
|
-
export async function isFileIsUpToDate(filePath, timeRangeSeconds) {
|
|
52
|
-
const fileUpdateTime = (await stat(filePath)).mtime.valueOf();
|
|
53
|
-
const currentTime = (new Date()).valueOf();
|
|
54
|
-
const differenceInMilliseconds = currentTime - fileUpdateTime;
|
|
55
|
-
const differenceInSeconds = differenceInMilliseconds / 1000;
|
|
56
|
-
return differenceInSeconds <= timeRangeSeconds;
|
|
57
|
-
}
|
|
58
|
-
export async function computeFileSha256Hex(filePath) {
|
|
59
|
-
const resultOpenPromise = new OpenPromise();
|
|
60
|
-
const crypto = await import('crypto');
|
|
61
|
-
const hash = crypto.createHash('sha256');
|
|
62
|
-
const readStream = createReadStream(filePath);
|
|
63
|
-
readStream.on('data', data => hash.update(data));
|
|
64
|
-
readStream.on('error', error => resultOpenPromise.reject(error));
|
|
65
|
-
readStream.on('end', () => resultOpenPromise.resolve(hash.digest('hex')));
|
|
66
|
-
return resultOpenPromise.promise;
|
|
67
|
-
}
|
|
68
|
-
export async function readAndParseJsonFile(jsonFilePath, useJson5 = false) {
|
|
69
|
-
const fileContent = await readFile(jsonFilePath, { encoding: 'utf-8' });
|
|
70
|
-
if (useJson5) {
|
|
71
|
-
const { default: JSON5 } = await import('json5');
|
|
72
|
-
return JSON5.parse(fileContent);
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
return JSON.parse(fileContent);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
export async function writeFile(filePath, data, options) {
|
|
79
|
-
const fileDir = path.dirname(filePath);
|
|
80
|
-
await ensureDir(fileDir);
|
|
81
|
-
return nodeFsWriteFile(filePath, data, options);
|
|
82
|
-
}
|
|
83
|
-
export async function writeFileSafe(filePath, data, options) {
|
|
84
|
-
const tempDir = getAppTempDir(appName);
|
|
85
|
-
const tempFilePath = path.join(tempDir, `${getRandomHexString(16)}.partial`);
|
|
86
|
-
await writeFile(tempFilePath, data, options);
|
|
87
|
-
await move(tempFilePath, filePath);
|
|
88
|
-
}
|
|
89
164
|
export function getAppDataDir(appName) {
|
|
90
165
|
let dataDir;
|
|
91
166
|
const platform = process.platform;
|
|
92
167
|
const homeDir = os.homedir();
|
|
93
168
|
if (platform == 'win32') {
|
|
94
|
-
dataDir =
|
|
169
|
+
dataDir = joinPath(homeDir, 'AppData', 'Local', appName);
|
|
95
170
|
}
|
|
96
171
|
else if (platform == 'darwin') {
|
|
97
|
-
dataDir =
|
|
172
|
+
dataDir = joinPath(homeDir, 'Library', 'Application Support', appName);
|
|
98
173
|
}
|
|
99
174
|
else if (platform == 'linux') {
|
|
100
|
-
dataDir =
|
|
175
|
+
dataDir = joinPath(homeDir, '.local', 'share', appName);
|
|
101
176
|
}
|
|
102
177
|
else {
|
|
103
178
|
throw new Error(`Unsupport platform ${platform}`);
|
|
104
179
|
}
|
|
105
180
|
return dataDir;
|
|
106
181
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
if (rootPathStat.isDirectory()) {
|
|
111
|
-
const fileList = await readdir(rootPath);
|
|
112
|
-
for (const filename of fileList) {
|
|
113
|
-
const filePath = path.join(rootPath, filename);
|
|
114
|
-
await chmodRecursive(filePath, newMode);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
export async function ensureDir(dirPath) {
|
|
119
|
-
dirPath = path.normalize(dirPath);
|
|
120
|
-
if (existsSync(dirPath)) {
|
|
121
|
-
const dirStats = await stat(dirPath);
|
|
122
|
-
if (!dirStats.isDirectory()) {
|
|
123
|
-
throw new Error(`The path '${dirPath}' exists but is not a directory.`);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
127
|
-
return fsExtra.ensureDir(dirPath);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
182
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
183
|
+
// Copy operations
|
|
184
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
130
185
|
export async function move(source, dest) {
|
|
131
|
-
source =
|
|
132
|
-
dest =
|
|
186
|
+
source = normalizePath(source);
|
|
187
|
+
dest = normalizePath(dest);
|
|
133
188
|
if (existsSync(dest)) {
|
|
134
189
|
const destPathExistsAndIsWritable = await existsAndIsWritable(dest);
|
|
135
190
|
if (!destPathExistsAndIsWritable) {
|
|
@@ -137,7 +192,7 @@ export async function move(source, dest) {
|
|
|
137
192
|
}
|
|
138
193
|
}
|
|
139
194
|
else {
|
|
140
|
-
const destDir =
|
|
195
|
+
const destDir = parsePath(dest).dir;
|
|
141
196
|
const destDirIsWritable = await testDirectoryIsWritable(destDir);
|
|
142
197
|
if (!destDirIsWritable) {
|
|
143
198
|
throw new Error(`The directory ${destDir} is not writable. There may be a permissions issue.`);
|
|
@@ -145,6 +200,9 @@ export async function move(source, dest) {
|
|
|
145
200
|
}
|
|
146
201
|
return fsExtra.move(source, dest, { overwrite: true });
|
|
147
202
|
}
|
|
203
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
204
|
+
// Misc operations
|
|
205
|
+
///////////////////////////////////////////////////////////////////////////////////////////
|
|
148
206
|
export async function existsAndIsWritable(targetPath) {
|
|
149
207
|
try {
|
|
150
208
|
await access(targetPath, gracefulFS.constants.W_OK);
|
|
@@ -154,31 +212,34 @@ export async function existsAndIsWritable(targetPath) {
|
|
|
154
212
|
}
|
|
155
213
|
return true;
|
|
156
214
|
}
|
|
157
|
-
export async function
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
await
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
215
|
+
export async function chmodRecursive(rootPath, newMode) {
|
|
216
|
+
const rootPathStat = await stat(rootPath);
|
|
217
|
+
await chmod(rootPath, newMode);
|
|
218
|
+
if (rootPathStat.isDirectory()) {
|
|
219
|
+
const fileList = await readdir(rootPath);
|
|
220
|
+
for (const filename of fileList) {
|
|
221
|
+
const filePath = joinPath(rootPath, filename);
|
|
222
|
+
await chmodRecursive(filePath, newMode);
|
|
223
|
+
}
|
|
165
224
|
}
|
|
166
|
-
return true;
|
|
167
225
|
}
|
|
168
|
-
export async function
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
226
|
+
export async function isFileIsUpToDate(filePath, maxTimeDifferenceSeconds) {
|
|
227
|
+
const fileUpdateTime = (await stat(filePath)).mtime.valueOf();
|
|
228
|
+
const currentTime = (new Date()).valueOf();
|
|
229
|
+
const differenceInMilliseconds = currentTime - fileUpdateTime;
|
|
230
|
+
const differenceInSeconds = differenceInMilliseconds / 1000;
|
|
231
|
+
return differenceInSeconds <= maxTimeDifferenceSeconds;
|
|
232
|
+
}
|
|
233
|
+
export async function computeFileSha256Hex(filePath) {
|
|
234
|
+
const crypto = await import('crypto');
|
|
235
|
+
const hash = crypto.createHash('sha256');
|
|
236
|
+
const fileReader = new FileReader(filePath);
|
|
237
|
+
const buffer = new Uint8Array(2 ** 16);
|
|
238
|
+
while (!fileReader.isFinished) {
|
|
239
|
+
const chunk = await fileReader.readChunk(buffer);
|
|
240
|
+
hash.update(chunk);
|
|
241
|
+
}
|
|
242
|
+
const result = hash.digest('hex');
|
|
243
|
+
return result;
|
|
183
244
|
}
|
|
184
245
|
//# sourceMappingURL=FileSystem.js.map
|