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


TypeScript fs.closeSync函数代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4:

 var onDone = (err: Error) => {
   remaining--;
   if (remaining === 0) {
     fs.closeSync(fd);
     for (var type in outFds) {
       fs.writeSync(outFds[type], '\n]\n');
       fs.closeSync(outFds[type]);
     }
     console.log('finished!');
   }
 }
开发者ID:fcrick,项目名称:tes-data,代码行数:11,代码来源:getAllByType.ts

示例5: 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

示例6: writeToBuffer

function writeToBuffer(filename, buffer) {
  const fd = fs.openSync(filename, 'r');
  const bytesRead = fs.readSync(fd, buffer, 0, buffer.length, 0);
  fs.closeSync(fd);

  return bytesRead;
}
开发者ID:nspragg,项目名称:filesniffer,代码行数:7,代码来源:isbinary.ts

示例7: function

		fs.open (filepath, 'r', function (err, fd) {
			if (!err) {
				// File already exits
				fs.closeSync (fd);
				resolve (null);
			}
			else {
				// File does not exist...create it
				var fs_write_stream = fs.createWriteStream (filepath);

				var gfs = Grid(conn.db);

				//read from mongodb
				var readstream = gfs.createReadStream ({_id: file._id});
				readstream.pipe (fs_write_stream);
				fs_write_stream.on ('close', function () {
					console.log ('file created: ' + filepath);
					resolve (null);
				});
				fs_write_stream.on ('error', function () {
					err = 'file creation error: ' + filepath;
					reject (err);
				});
			}
		});
开发者ID:roderickmonk,项目名称:rod-monk-sample-repo,代码行数:25,代码来源:ttcGridFS.ts

示例8: unlockChannelLock

function unlockChannelLock(): void {
	'use strict';
	if (channelLockFileDescriptor !== undefined) {
		fs.closeSync(channelLockFileDescriptor);
		channelLockFileDescriptor = undefined;
	}
}
开发者ID:data9824,项目名称:SavannaTalk,代码行数:7,代码来源:main.ts

示例9: 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

示例10: done_cb

 function done_cb(failed: boolean): void {
   print((failed ? '✗' : '✓'));
   if (failed) {
     fs.writeSync(outfile, '\n');
   }
   fs.closeSync(outfile);
 };
开发者ID:dk-dev,项目名称:doppio,代码行数:7,代码来源:test_runner.ts


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