本文整理汇总了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" });
}