本文整理匯總了TypeScript中pako.inflate函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript inflate函數的具體用法?TypeScript inflate怎麽用?TypeScript inflate使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了inflate函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: getZbook
async function getZbook(book : Book) : Promise<Database> {
let file = files[book.file];
if (!file) {
file = await localforage.getItem<BookFile>(book.file);
if (file) {
if (file.version !== book.file_version) {
// Update book in background.
fetchBinary(
book.url,
"Updating book " + book.name + "..."
).then(data => {
file.data = data;
// TODO: notify UI book has been updated
files[book.file] = file;
return localforage.setItem(book.file, file);
});
}
}
else {
file = {
version: book.file_version,
data: await fetchBinary(
book.url,
"Downloading book " + book.name + "..."
)
};
await localforage.setItem(book.file, file);
}
}
return new Database(inflate(file.data));
}
示例2: maybeDecompressGzip
export function maybeDecompressGzip(data: ArrayBuffer|ArrayBufferView) {
let byteView: Uint8Array;
if (data instanceof ArrayBuffer) {
byteView = new Uint8Array(data);
} else {
byteView = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
}
if (isGzipFormat(byteView)) {
return inflate(byteView);
}
return byteView;
}
示例3: decodeBossNpzChunk
export function decodeBossNpzChunk(chunk: VolumeChunk, response: ArrayBuffer) {
let parseResult = parseNpy(inflate(new Uint8Array(response)));
let chunkDataSize = chunk.chunkDataSize!;
let source = chunk.source!;
let {shape} = parseResult;
if (shape.length !== 3 || shape[0] !== chunkDataSize[2] ||
shape[1] !== chunkDataSize[1] || shape[2] !== chunkDataSize[0]) {
throw new Error(
`Shape ${JSON.stringify(shape)} does not match chunkDataSize ${vec3Key(chunkDataSize)}`);
}
let parsedDataType = parseResult.dataType.dataType;
let {spec} = source;
if (parsedDataType !== spec.dataType) {
throw new Error(
`Data type ${DataType[parsedDataType]} does not match expected data type ${DataType[spec.dataType]}`);
}
postProcessRawData(chunk, parseResult.data);
}
示例4: decodeChunk
function decodeChunk(chunk: VolumeChunk, response: ArrayBuffer, encoding: VolumeChunkEncoding) {
const dv = new DataView(response);
const mode = dv.getUint16(0, /*littleEndian=*/ false);
if (mode !== 0) {
throw new Error(`Unsupported mode: ${mode}.`);
}
const numDimensions = dv.getUint16(2, /*littleEndian=*/ false);
if (numDimensions !== 3) {
throw new Error(`Number of dimensions must be 3.`);
}
let offset = 4;
const shape = new Uint32Array(numDimensions);
for (let i = 0; i < numDimensions; ++i) {
shape[i] = dv.getUint32(offset, /*littleEndian=*/ false);
offset += 4;
}
chunk.chunkDataSize = vec3.fromValues(shape[0], shape[1], shape[2]);
let buffer = new Uint8Array(response, offset);
if (encoding === VolumeChunkEncoding.GZIP) {
buffer = inflate(buffer);
}
decodeRawChunk(chunk, buffer.buffer, Endianness.BIG, buffer.byteOffset, buffer.byteLength);
}
示例5: loadRaw
async loadRaw(hash : Hash) {
const raw = await super.loadRaw(hash);
return raw ? pako.inflate(raw) : undefined;
}
示例6: inflateBase64
export function inflateBase64(encoded: string): string {
const bytes = Base64.atob(encoded);
return pako.inflate(bytes, { to: "string" });
}