• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fs.openSync函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: copyFile

function copyFile(fromPath: string, toPath: string) {

    console.log("Copying from '" + fromPath + "' to '" + toPath);
    makePathTo(toPath);

    const fileSize = (fs.statSync(fromPath)).size,
        bufferSize = Math.min(0x10000, fileSize),
        buffer = new Buffer(bufferSize),
        progress = makeProgress(fileSize),
        handleFrom = fs.openSync(fromPath, "r"),
        handleTo = fs.openSync(toPath, "w");

    try {
        for (;;) {
            const got = fs.readSync(handleFrom, buffer, 0, bufferSize, null);
            if (got <= 0) break;
            fs.writeSync(handleTo, buffer, 0, got);
            progress(got);
        }
        progress(null);
    } finally {
        fs.closeSync(handleFrom);
        fs.closeSync(handleTo);
    }
}
开发者ID:danielearwicker,项目名称:mirrorball,代码行数:25,代码来源:mirrorball.ts


示例2: copyFile

function copyFile(sourceFile, destPath): void {
    checkFileCopy(sourceFile, destPath);

    var filename = path.basename(sourceFile);

    if (fs.existsSync(destPath)) {
        if (fs.lstatSync(destPath).isDirectory()) {
            destPath += "/" + filename;
        }
    } else {
        if (destPath[destPath.length - 1] === "/" || destPath[destPath.length - 1] === "\\") {
            mkdirParentsSync(destPath);
            destPath += filename;
        } else {
            mkdirParentsSync(path.dirname(destPath));
        }
    }

    var bufLength = 64 * 1024;
    var buff = new Buffer(bufLength);

    var fdr = fs.openSync(sourceFile, "r");
    var fdw = fs.openSync(destPath, "w");
    var bytesRead = 1;
    var pos = 0;
    while (bytesRead > 0) {
        bytesRead = fs.readSync(fdr, buff, 0, bufLength, pos);
        fs.writeSync(fdw, buff, 0, bytesRead);
        pos += bytesRead;
    }
    fs.closeSync(fdr);
    fs.closeSync(fdw);
}
开发者ID:PlayFab,项目名称:SDKGenerator,代码行数:33,代码来源:generate.ts


示例3: it

 it('should not remove files if nothing is matched', () => {
   fs.closeSync(fs.openSync(path.resolve(tmpDir, 'bar-123'), 'w'));
   fs.closeSync(fs.openSync(path.resolve(tmpDir, 'bar-456'), 'w'));
   fs.closeSync(fs.openSync(path.resolve(tmpDir, 'bar-789'), 'w'));
   expect(removeFiles(tmpDir, [/zebra-.*/g])).toBe('');
   expect(fs.readdirSync(tmpDir).length).toBe(3);
 });
开发者ID:angular,项目名称:webdriver-manager,代码行数:7,代码来源:file_utils.spec-int.ts


示例4: beforeAll

 beforeAll(() => {
   // create the directory
   try {
     fs.mkdirSync(tmpDir);
   } catch (err) {
   }
   // create files that should be deleted.
   fs.closeSync(fs.openSync(path.resolve(tmpDir, 'chromedriver_2.41'), 'w'));
   fs.closeSync(
       fs.openSync(path.resolve(tmpDir, 'chromedriver_foo.zip'), 'w'));
   fs.closeSync(
       fs.openSync(path.resolve(tmpDir, 'chromedriver.config.json'), 'w'));
   fs.closeSync(fs.openSync(path.resolve(tmpDir, 'chromedriver.xml'), 'w'));
 });
开发者ID:angular,项目名称:webdriver-manager,代码行数:14,代码来源:clean.spec-int.ts


示例5: convert

function convert(inFilename, outFilename) {
  let inFile = fs.openSync(inFilename, 'r');
  let outFile = fs.openSync(outFilename, 'w');
  return new Promise((resolve, reject) => {
    runCmd('sqlite3', [cluesDb], {
      stdio: [inFile, outFile, 'inherit']
    }, (err) => {
      fs.closeSync(inFile);
      fs.closeSync(outFile);
      if (err) { return reject(err); }
      resolve();
    });
  });
};
开发者ID:j-party,项目名称:game,代码行数:14,代码来源:convert-database.ts


示例6: latestVersion

    latestVersion("mirakurun").then(latest => {

        if (!req.query.force && current === latest) {
            api.responseError(res, 409, "Update Nothing");
            return;
        }

        let command;
        const args = [
            "install",
            "mirakurun@latest",
            "-g",
            "--production"
        ];
        if (process.platform === "win32") {
            command = "npm.cmd";
        } else {
            command = "npm";
            args.push("--unsafe");
        }

        res.setHeader("Content-Type", "text/plain; charset=utf-8");
        res.status(202);
        res.write("Updating...\n");

        const path = join(tmpdir(), "Mirakurun_Updating.log");
        if (existsSync(path) === true) {
            unlinkSync(path);
        }

        const out = openSync(path, "a");
        const err = openSync(path, "a");

        res.write(`> ${command} ${args.join(" ")}\n\n`);

        const npm = spawn(command, args, {
            detached: true,
            stdio: ["ignore", out, err]
        });
        npm.unref();

        const tail = new Tail(path);
        tail.on("line", data => res.write(data + "\n"));

        req.once("close", () => {
            tail.removeAllListener("line");
            tail.unwatch();
        });
    });
开发者ID:tosono,项目名称:Mirakurun,代码行数:49,代码来源:update.ts


示例7: touch

export function touch(filename: string): any {
  try {
    return closeSync(openSync(filename, 'w'));
  } catch (err) {
    console.log('file already exists');
  }
}
开发者ID:mshick,项目名称:arrivals-osx,代码行数:7,代码来源:utils.ts


示例8: spawnNpmInstall

function spawnNpmInstall(version: string): ChildProcess {

    let command = "npm";
    const args = [
        "install",
        `${pkg.name}@${version}`,
        "-g",
        "--production"
    ];
    if (process.platform === "win32") {
        command = "npm.cmd";
    } else {
        args.push("--unsafe-perm");
    }

    console.log(">", command, ...args);

    let out: number;
    if (process.env.UPDATER_LOG_PATH) {
        out = openSync(process.env.UPDATER_LOG_PATH, "a");
    }

    const npm = spawn(command, args, {
        detached: true,
        stdio: [
            "ignore",
            out || process.stdout,
            out || process.stderr
        ]
    });
    npm.unref();

    return npm;
}
开发者ID:kanreisa,项目名称:Mirakurun,代码行数:34,代码来源:updater.ts


示例9: it

 it('fs.write should work with util.promisify', (done: DoneFn) => {
   const promisifyWrite = util.promisify(write);
   const dest = __filename + 'write';
   const fd = openSync(dest, 'a');
   const stats = fstatSync(fd);
   const chunkSize = 512;
   const buffer = new Buffer(chunkSize);
   for (let i = 0; i < chunkSize; i++) {
     buffer[i] = 0;
   }
   // fd, buffer, offset, length, position, callback
   promisifyWrite(fd, buffer, 0, chunkSize, 0)
       .then(
           (value) => {
             expect(value.bytesWritten).toBe(chunkSize);
             closeSync(fd);
             unlinkSync(dest);
             done();
           },
           err => {
             closeSync(fd);
             unlinkSync(dest);
             fail(`should not be here with error: ${error}.`);
           });
 });
开发者ID:angular,项目名称:zone.js,代码行数:25,代码来源:fs.spec.ts


示例10: writeFileSync

export function writeFileSync(path: string, data: string | Buffer, options?: IWriteFileOptions): void {
	const ensuredOptions = ensureWriteOptions(options);

	if (ensuredOptions.encoding) {
		data = encode(data, ensuredOptions.encoding.charset, { addBOM: ensuredOptions.encoding.addBOM });
	}

	if (!canFlush) {
		return fs.writeFileSync(path, data, { mode: ensuredOptions.mode, flag: ensuredOptions.flag });
	}

	// Open the file with same flags and mode as fs.writeFile()
	const fd = fs.openSync(path, ensuredOptions.flag, ensuredOptions.mode);

	try {

		// It is valid to pass a fd handle to fs.writeFile() and this will keep the handle open!
		fs.writeFileSync(fd, data);

		// Flush contents (not metadata) of the file to disk
		try {
			fs.fdatasyncSync(fd);
		} catch (syncError) {
			console.warn('[node.js fs] fdatasyncSync is now disabled for this session because it failed: ', syncError);
			canFlush = false;
		}
	} finally {
		fs.closeSync(fd);
	}
}
开发者ID:PKRoma,项目名称:vscode,代码行数:30,代码来源:pfs.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs.read函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs.open函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap