@opensumi/ide-utils
Advanced tools
Comparing version 2.18.8 to 2.18.9-next-1657174681.0
@@ -35,2 +35,6 @@ export declare class BinaryBuffer { | ||
export declare function writeUInt8(destination: Uint8Array, value: number, offset: number): void; | ||
/** Decodes base64 to a uint8 array. URL-encoded and unpadded base64 is allowed. */ | ||
export declare function decodeBase64(encoded: string): BinaryBuffer; | ||
/** Encodes a buffer to a base64 string. */ | ||
export declare function encodeBase64({ buffer }: BinaryBuffer, padded?: boolean, urlSafe?: boolean): string; | ||
//# sourceMappingURL=buffer.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.writeUInt8 = exports.readUInt8 = exports.writeUInt32LE = exports.readUInt32LE = exports.writeUInt32BE = exports.readUInt32BE = exports.writeUInt16LE = exports.readUInt16LE = exports.BinaryBuffer = void 0; | ||
exports.encodeBase64 = exports.decodeBase64 = exports.writeUInt8 = exports.readUInt8 = exports.writeUInt32LE = exports.readUInt32LE = exports.writeUInt32BE = exports.readUInt32BE = exports.writeUInt16LE = exports.readUInt16LE = exports.BinaryBuffer = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -174,2 +174,103 @@ /* --------------------------------------------------------------------------------------------- | ||
exports.writeUInt8 = writeUInt8; | ||
/** Decodes base64 to a uint8 array. URL-encoded and unpadded base64 is allowed. */ | ||
function decodeBase64(encoded) { | ||
let building = 0; | ||
let remainder = 0; | ||
let bufi = 0; | ||
// The simpler way to do this is `Uint8Array.from(atob(str), c => c.charCodeAt(0))`, | ||
// but that's about 10-20x slower than this function in current Chromium versions. | ||
const buffer = new Uint8Array(Math.floor((encoded.length / 4) * 3)); | ||
const append = (value) => { | ||
switch (remainder) { | ||
case 3: | ||
buffer[bufi++] = building | value; | ||
remainder = 0; | ||
break; | ||
case 2: | ||
buffer[bufi++] = building | (value >>> 2); | ||
building = value << 6; | ||
remainder = 3; | ||
break; | ||
case 1: | ||
buffer[bufi++] = building | (value >>> 4); | ||
building = value << 4; | ||
remainder = 2; | ||
break; | ||
default: | ||
building = value << 2; | ||
remainder = 1; | ||
} | ||
}; | ||
for (let i = 0; i < encoded.length; i++) { | ||
const code = encoded.charCodeAt(i); | ||
// See https://datatracker.ietf.org/doc/html/rfc4648#section-4 | ||
// This branchy code is about 3x faster than an indexOf on a base64 char string. | ||
if (code >= 65 && code <= 90) { | ||
append(code - 65); // A-Z starts ranges from char code 65 to 90 | ||
} | ||
else if (code >= 97 && code <= 122) { | ||
append(code - 97 + 26); // a-z starts ranges from char code 97 to 122, starting at byte 26 | ||
} | ||
else if (code >= 48 && code <= 57) { | ||
append(code - 48 + 52); // 0-9 starts ranges from char code 48 to 58, starting at byte 52 | ||
} | ||
else if (code === 43 || code === 45) { | ||
append(62); // "+" or "-" for URLS | ||
} | ||
else if (code === 47 || code === 95) { | ||
append(63); // "/" or "_" for URLS | ||
} | ||
else if (code === 61) { | ||
break; // "=" | ||
} | ||
else { | ||
throw new SyntaxError(`Unexpected base64 character ${encoded[i]}`); | ||
} | ||
} | ||
const unpadded = bufi; | ||
while (remainder > 0) { | ||
append(0); | ||
} | ||
// slice is needed to account for overestimation due to padding | ||
return BinaryBuffer.wrap(buffer).slice(0, unpadded); | ||
} | ||
exports.decodeBase64 = decodeBase64; | ||
const base64Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; | ||
const base64UrlSafeAlphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | ||
/** Encodes a buffer to a base64 string. */ | ||
function encodeBase64({ buffer }, padded = true, urlSafe = false) { | ||
const dictionary = urlSafe ? base64UrlSafeAlphabet : base64Alphabet; | ||
let output = ''; | ||
const remainder = buffer.byteLength % 3; | ||
let i = 0; | ||
for (; i < buffer.byteLength - remainder; i += 3) { | ||
const a = buffer[i + 0]; | ||
const b = buffer[i + 1]; | ||
const c = buffer[i + 2]; | ||
output += dictionary[a >>> 2]; | ||
output += dictionary[((a << 4) | (b >>> 4)) & 0b111111]; | ||
output += dictionary[((b << 2) | (c >>> 6)) & 0b111111]; | ||
output += dictionary[c & 0b111111]; | ||
} | ||
if (remainder === 1) { | ||
const a = buffer[i + 0]; | ||
output += dictionary[a >>> 2]; | ||
output += dictionary[(a << 4) & 0b111111]; | ||
if (padded) { | ||
output += '=='; | ||
} | ||
} | ||
else if (remainder === 2) { | ||
const a = buffer[i + 0]; | ||
const b = buffer[i + 1]; | ||
output += dictionary[a >>> 2]; | ||
output += dictionary[((a << 4) | (b >>> 4)) & 0b111111]; | ||
output += dictionary[(b << 2) & 0b111111]; | ||
if (padded) { | ||
output += '='; | ||
} | ||
} | ||
return output; | ||
} | ||
exports.encodeBase64 = encodeBase64; | ||
//# sourceMappingURL=buffer.js.map |
@@ -1,16 +0,1 @@ | ||
/** ****************************************************************************** | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
import { Event, Emitter } from './event'; | ||
@@ -17,0 +2,0 @@ export declare class DisposableStore implements IDisposable { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RefCountedDisposable = exports.MutableDisposable = exports.DisposableCollection = exports.Disposable = exports.toDisposable = exports.combinedDisposable = exports.dispose = exports.isDisposable = exports.DisposableStore = void 0; | ||
/** ****************************************************************************** | ||
* Copyright (C) 2017 TypeFox and others. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the Eclipse | ||
* Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
* with the GNU Classpath Exception which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
********************************************************************************/ | ||
const event_1 = require("./event"); | ||
@@ -207,10 +192,14 @@ // DisposableStore 是从 vscode lifecycle 中复制而来 | ||
} | ||
const toPromise = []; | ||
this.disposingElements = true; | ||
while (!this.disposed) { | ||
try { | ||
this.disposables.pop().dispose(); | ||
const maybePromise = this.disposables.pop().dispose(); | ||
if (maybePromise) { | ||
toPromise.push(maybePromise); | ||
} | ||
} | ||
catch (e) { | ||
// eslint-disable-next-line no-console | ||
console.error(e); | ||
console.error('DisposableCollection.dispose error', e); | ||
} | ||
@@ -220,2 +209,3 @@ } | ||
this.checkDisposed(); | ||
return Promise.all(toPromise); | ||
} | ||
@@ -222,0 +212,0 @@ push(disposable) { |
@@ -29,3 +29,3 @@ export * from './ansi'; | ||
export * from './progress'; | ||
export * from './promise-util'; | ||
export * from './promises'; | ||
export * from './sequence'; | ||
@@ -32,0 +32,0 @@ export * from './types'; |
@@ -33,3 +33,3 @@ "use strict"; | ||
tslib_1.__exportStar(require("./progress"), exports); | ||
tslib_1.__exportStar(require("./promise-util"), exports); | ||
tslib_1.__exportStar(require("./promises"), exports); | ||
tslib_1.__exportStar(require("./sequence"), exports); | ||
@@ -36,0 +36,0 @@ tslib_1.__exportStar(require("./types"), exports); |
{ | ||
"name": "@opensumi/ide-utils", | ||
"version": "2.18.8", | ||
"version": "2.18.9-next-1657174681.0", | ||
"files": [ | ||
@@ -25,3 +25,3 @@ "lib" | ||
}, | ||
"gitHead": "29a34ce3d08f9a284970a6225d2d9995514fd508" | ||
"gitHead": "0a0f56a3dd4c918f2d0c119a1c15b5a011c79f43" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
742797
11842
2