当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript zlib.gzipSync函数代码示例

本文整理汇总了TypeScript中zlib.gzipSync函数的典型用法代码示例。如果您正苦于以下问题:TypeScript gzipSync函数的具体用法?TypeScript gzipSync怎么用?TypeScript gzipSync使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了gzipSync函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: encodeToGZIP

function encodeToGZIP(buffer: Buffer, response: http.ServerResponse) 
{
    let buf = zlib.gzipSync(buffer);
    response.setHeader('Content-Encoding', 'gzip');
    response.setHeader('Content-Length', buf.length.toString());
    return buf;
}
开发者ID:Kasperki,项目名称:NodeBlog,代码行数:7,代码来源:FileServer.ts

示例2: gzipSync

const createArchive = (buildNum: number, prNum: number, sha: string) => {
  logger.log('createArchive', buildNum, prNum, sha);
  const pack = tar.pack();
  pack.entry({name: 'index.html'}, `BUILD: ${buildNum} | PR: ${prNum} | SHA: ${sha} | File: /index.html`);
  pack.entry({name: 'foo/bar.js'}, `BUILD: ${buildNum} | PR: ${prNum} | SHA: ${sha} | File: /foo/bar.js`);
  pack.finalize();
  const zip = gzipSync(pack.read());
  return zip;
};
开发者ID:DeepanParikh,项目名称:angular,代码行数:9,代码来源:mock-external-apis.ts

示例3: register

const buildServerBinaryCopy = register("build:server:binary:copy", async (runner) => {
	const cliPath = path.join(pkgsPath, "server");
	const cliBuildPath = path.join(cliPath, "build");
	fse.removeSync(cliBuildPath);
	fse.mkdirpSync(path.join(cliBuildPath, "extensions"));
	const bootstrapForkPath = path.join(pkgsPath, "vscode", "out", "bootstrap-fork.js");
	const webOutputPath = path.join(pkgsPath, "web", "out");
	const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
	const nodePtyModule = path.join(pkgsPath, "protocol", "node_modules", "node-pty-prebuilt", "build", "Release", "pty.node");
	const spdlogModule = path.join(pkgsPath, "protocol", "node_modules", "spdlog", "build", "Release", "spdlog.node");
	let ripgrepPath = path.join(pkgsPath, "..", "lib", "vscode", "node_modules", "vscode-ripgrep", "bin", "rg");
	if (isWin) {
		ripgrepPath += ".exe";
	}

	if (!fs.existsSync(nodePtyModule)) {
		throw new Error("Could not find pty.node. Ensure all packages have been installed");
	}
	if (!fs.existsSync(spdlogModule)) {
		throw new Error("Could not find spdlog.node. Ensure all packages have been installed");
	}
	if (!fs.existsSync(webOutputPath)) {
		throw new Error("Web bundle must be built");
	}
	if (!fs.existsSync(defaultExtensionsPath)) {
		throw new Error("Default extensions must be built");
	}
	if (!fs.existsSync(bootstrapForkPath)) {
		throw new Error("Bootstrap fork must exist");
	}
	if (!fs.existsSync(ripgrepPath)) {
		throw new Error("Ripgrep must exist");
	}
	fse.copySync(defaultExtensionsPath, path.join(cliBuildPath, "extensions"));
	fs.writeFileSync(path.join(cliBuildPath, "bootstrap-fork.js.gz"), zlib.gzipSync(fs.readFileSync(bootstrapForkPath)));
	const cpDir = (dir: string, subdir: "auth" | "unauth", rootPath: string): void => {
		const stat = fs.statSync(dir);
		if (stat.isDirectory()) {
			const paths = fs.readdirSync(dir);
			paths.forEach((p) => cpDir(path.join(dir, p), subdir, rootPath));
		} else if (stat.isFile()) {
			const newPath = path.join(cliBuildPath, "web", subdir, path.relative(rootPath, dir));
			fse.mkdirpSync(path.dirname(newPath));
			fs.writeFileSync(newPath + ".gz", zlib.gzipSync(fs.readFileSync(dir)));
		} else {
			// Nothing
		}
	};
	cpDir(webOutputPath, "auth", webOutputPath);
	cpDir(browserAppOutputPath, "unauth", browserAppOutputPath);
	fse.mkdirpSync(path.join(cliBuildPath, "dependencies"));
	fse.copySync(nodePtyModule, path.join(cliBuildPath, "dependencies", "pty.node"));
	fse.copySync(spdlogModule, path.join(cliBuildPath, "dependencies", "spdlog.node"));
	fse.copySync(ripgrepPath, path.join(cliBuildPath, "dependencies", "rg"));
});
开发者ID:AhmadAlyTanany,项目名称:code-server,代码行数:55,代码来源:tasks.ts

示例4: cpDir

	const cpDir = (dir: string, subdir: "auth" | "unauth", rootPath: string): void => {
		const stat = fs.statSync(dir);
		if (stat.isDirectory()) {
			const paths = fs.readdirSync(dir);
			paths.forEach((p) => cpDir(path.join(dir, p), subdir, rootPath));
		} else if (stat.isFile()) {
			const newPath = path.join(cliBuildPath, "web", subdir, path.relative(rootPath, dir));
			fse.mkdirpSync(path.dirname(newPath));
			fs.writeFileSync(newPath + ".gz", zlib.gzipSync(fs.readFileSync(dir)));
		} else {
			// Nothing
		}
	};
开发者ID:AhmadAlyTanany,项目名称:code-server,代码行数:13,代码来源:tasks.ts

示例5: it

        it('should decompress gzip messages', async () => {
          const data = {
            messageType: ClientServer.MessageType.PING,
            ping: {}
          }
          const dataMessage = ClientServer.encode(ClientServer.fromObject(data)).finish()
          const message: IClientServerMessage = {
            compression: Compression.GZIP,
            compressedData: zlib.gzipSync(dataMessage as Buffer)
          }
          const encodedMessage = ClientServerMessage.encode(ClientServerMessage.fromObject(message)).finish()

          await fnMocks.message(encodedMessage)

          expect(wsMock.send).toHaveBeenCalledWith(new Uint8Array(encodedMessage), { binary: true })
        })
开发者ID:Tarnadas,项目名称:net64plus-server,代码行数:16,代码来源:Client.spec.ts

示例6: stringifyId

		this.context.reflectionById.forEach(reflection => {
			if ((reflection as ExcludedReflection)[ExcludedFlag]) {
				return
			}

			if (
				enableSearch &&
				IsSearchable[reflection.kind] &&
				reflection.id &&
				// Make only top-level items searchable
				reflection.id.every(id => IsSearchable[id.kind])
			) {
				const packageKey = `${reflection.id[0].name}#${reflection.id[0].version}`
				if (!search.packages[packageKey] || !alreadyRecreated[packageKey]) {
					search.packages[packageKey] = []
					alreadyRecreated[packageKey] = true
				}

				search.packages[packageKey].push(idFromPath(reflection.id))
			}

			if (!IsWritable[reflection.kind]) {
				return
			}

			const folder = path.join(outDir, stringifyId(reflection.id!))
			const fileName = path.join(folder, 'index.json')

			fileSystem.mkdirpSync(folder)

			const meta: ReflectionWithMetadata = {
				metadata: {
					formatVersion
				},
				reflection
			}

			let fileContent: string | Buffer = JSON.stringify(meta, null, 4)

			if (gzip) {
				fileContent = gzipSync(fileContent, {
					level: 1
				})
			}

			fileSystem.writeFileSync(fileName, fileContent)
		})
开发者ID:docscript,项目名称:docscript,代码行数:47,代码来源:writer.ts

示例7: stream_readable_pipe_test

function stream_readable_pipe_test() {
    var r = fs.createReadStream('file.txt');
    var z = zlib.createGzip();
    var w = fs.createWriteStream('file.txt.gz');
    r.pipe(z).pipe(w);
    r.close();
}


////////////////////////////////////////////////////
/// zlib tests : http://nodejs.org/api/zlib.html ///
////////////////////////////////////////////////////

namespace zlib_tests {
    {
        const gzipped = zlib.gzipSync('test');
        const unzipped = zlib.gunzipSync(gzipped.toString());
    }

    {
        const deflate = zlib.deflateSync('test');
        const inflate = zlib.inflateSync(deflate.toString());
    }
}

////////////////////////////////////////////////////////
/// Crypto tests : http://nodejs.org/api/crypto.html ///
////////////////////////////////////////////////////////

namespace crypto_tests {
    {
开发者ID:DenisCarriere,项目名称:DefinitelyTyped,代码行数:31,代码来源:node-tests.ts

示例8: write

/**
 * Write contents into a compressed file.
 *
 * @params {String} filename
 * @params {String} result
 */
function write(filename: string, result: any) {
    let jsonString = JSON.stringify(result);
    let content = zlib.gzipSync(jsonString as any);
    return fs.writeFileSync(filename, content);
}
开发者ID:TheLarkInn,项目名称:awesome-typescript-loader,代码行数:11,代码来源:cache.ts

示例9: gzipDataToFile

function gzipDataToFile(path, data, options) {
    var compressedData = zlib.gzipSync(data, options);
    console.info("--- GZIP complete. Compressed file size: " + compressedData.length);
    writeDataToFile(path + ".gz", compressedData);
}
开发者ID:Dyas,项目名称:challenge_word_classifier,代码行数:5,代码来源:PackData.ts

示例10: inflateRawSync

);
const inflatedRaw: Buffer = inflateRawSync(deflateRawSync(compressMe));
const inflatedRawString: Buffer = inflateRawSync(deflateRawSync(compressMeString));

// gzip

gzip(compressMe, (err: Error | null, result: Buffer) => gunzip(result, (err: Error | null, result: Buffer) => result));
gzip(
    compressMe,
    { finishFlush: constants.Z_SYNC_FLUSH },
    (err: Error | null, result: Buffer) => gunzip(
        result, { finishFlush: constants.Z_SYNC_FLUSH },
        (err: Error | null, result: Buffer) => result
    )
);
const gunzipped: Buffer = gunzipSync(gzipSync(compressMe));

unzip(compressMe, (err: Error | null, result: Buffer) => result);
unzip(compressMe, { finishFlush: constants.Z_SYNC_FLUSH }, (err: Error | null, result: Buffer) => result);
const unzipped: Buffer = unzipSync(compressMe);

const bOpts: BrotliOptions = {
    chunkSize: 123,
    flush: 123123,
    params: {
        [constants.BROTLI_PARAM_LARGE_WINDOW]: true,
        [constants.BROTLI_PARAM_NPOSTFIX]: 123,
    },
    finishFlush: 123123,
};
开发者ID:CNBoland,项目名称:DefinitelyTyped,代码行数:30,代码来源:zlib.ts


注:本文中的zlib.gzipSync函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。