Skip to content

Commit 442f356

Browse files
committed
Update format.js
1 parent a814e57 commit 442f356

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

bin/format.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,12 @@ function makeSemVer([major, minor, patch]) {
162162
return new SemVer(major + '.' + minor + '.' + patch);
163163
}
164164

165-
function corrupted(isEncrypted, extra) {
165+
function corrupted(isEncrypted, isWindows, extra) {
166166
throw new Error(prefix+(
167-
isEncrypted ? 'Input key is invalid or i' : 'I'
167+
isEncrypted ? (
168+
isWindows ? 'Password is incorrect' :
169+
'Input key is invalid'
170+
) + ' or i' : 'I'
168171
)+'nput file is corrupted.'+(
169172
extra ? ' ('+extra+')' : ''
170173
));
@@ -173,8 +176,9 @@ function corrupted(isEncrypted, extra) {
173176
/**
174177
* @param {Uint8Array<ArrayBuffer>} uint8
175178
* @param {() => Promise<string>} onEncrypted
179+
* @param {boolean} isWindows
176180
*/
177-
export async function fromFile(uint8, onEncrypted) {
181+
export async function fromFile(uint8, onEncrypted, isWindows) {
178182
const d = new TextDecoder();
179183

180184
const filetype = d.decode(uint8.subarray(0,5));
@@ -212,14 +216,14 @@ export async function fromFile(uint8, onEncrypted) {
212216
let func = fromInt32;
213217
function read() {
214218
if (i >= uint8.length) return null;
215-
if (i + legnthLength > uint8.length) corrupted(encrypted);
219+
if (i + legnthLength > uint8.length) corrupted(encrypted, isWindows);
216220

217221
const length = func(uint8.subarray(i, i + legnthLength));
218222
i += legnthLength;
219223

220224
if (length == 0) return 0;
221225

222-
if (i + length > uint8.length) corrupted(encrypted);
226+
if (i + length > uint8.length) corrupted(encrypted, isWindows);
223227

224228
const data = UI8AtoB64(uint8.subarray(i, i + length));
225229
i += length;
@@ -242,15 +246,15 @@ export async function fromFile(uint8, onEncrypted) {
242246
if (path == null) break;
243247

244248
const content = read();
245-
if (content == null) corrupted(encrypted);
249+
if (content == null) corrupted(encrypted, isWindows);
246250

247251
if (content == 0) dirs.push(path);
248252
else {
249253
const outputFile = [path == 0 ? '' : path, content];
250254

251255
if (hasMeta) {
252256
const mtime = read();
253-
if (mtime == null || mtime == 0) corrupted(encrypted);
257+
if (mtime == null || mtime == 0) corrupted(encrypted, isWindows);
254258

255259
outputFile.push(parseInt(convertBase(mtime, 64, 10), 10));
256260
} else outputFile.push(Math.floor(Date.now() / 1000));
@@ -262,7 +266,7 @@ export async function fromFile(uint8, onEncrypted) {
262266
}
263267

264268
if (typeof checksum != 'undefined' && checksum != crc32.str(JSON.stringify(files))) {
265-
corrupted(encrypted, 'CRC32');
269+
corrupted(encrypted, isWindows, 'CRC32');
266270
}
267271

268272
return {

0 commit comments

Comments
 (0)