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


TypeScript fs.writeSync函数代码示例

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


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

示例1: copy

export function copy(source: string, target: string, log:Function = function() {}) {
  let sourceEntry = scan_entry(path.resolve(source))
  let targetEntry = scan_entry(path.resolve(target))

  switch(sourceEntry.type) {
    case "null":
      throw Error(`unable to copy file ${sourceEntry.fullname} because it doesn't exist.`)
    case "directory":
      throw Error(`unable to copy file ${sourceEntry.fullname} because it is a directory.`)
    case "file":
      break
  }
  
  switch(targetEntry.type) {
    case "directory":
      throw Error(`unable to copy file ${sourceEntry.fullname} to ${targetEntry.fullname} because a directory exists at the target.`)
    case "file":
      fs.unlinkSync(targetEntry.fullname)
      break;
    case "null":
      break
  }
  
  log(`copying: ${sourceEntry.fullname} to ${targetEntry.fullname}`)

  let BUF_LENGTH = 64 * 1024
  let buff       = new Buffer(BUF_LENGTH)
  let fdr        = fs.openSync(sourceEntry.fullname, 'r')
  let fdw        = fs.openSync(targetEntry.fullname, 'w')
  let bytesRead  = 1
  let pos        = 0
  while (bytesRead > 0) {
    bytesRead = fs.readSync(fdr, buff, 0, BUF_LENGTH, pos)
    fs.writeSync(fdw,buff, 0, bytesRead)
    pos += bytesRead
  }
  fs.closeSync(fdr)
  fs.closeSync(fdw)
}
开发者ID:sinclairzx81,项目名称:tasksmith-js,代码行数:39,代码来源:copy.ts

示例2: prgo

function prgo(s: string) {
  return (fs.writeSync(fde, s))
}
开发者ID:Go-zh,项目名称:tools,代码行数:3,代码来源:go.ts

示例3: prb

function prb(s: string) {
  return (fs.writeSync(fdb, s))
}
开发者ID:Go-zh,项目名称:tools,代码行数:3,代码来源:go.ts

示例4: pra

function pra(s: string) {
  return (fs.writeSync(fda, s))
}
开发者ID:Go-zh,项目名称:tools,代码行数:3,代码来源:go.ts

示例5: write

function write(fileName, content) {
    var fd = fs.openSync(path.join(fontRoot, fileName), 'w');
    fs.writeSync(fd, content);
    fs.closeSync(fd);
}
开发者ID:Microsoft,项目名称:maker.js,代码行数:5,代码来源:gen.ts

示例6: function

// Header
fs.writeSync(outfile, `
  // Generated by scripts/make_fixture_loader.ts
  // Used by unit testing only. Preloads needed testing files.
  import * as BrowserFS from '../../src/index';
  const fs = BrowserFS.BFSRequire('fs');
  export default function (): void {
    let nextDir: number;
    let dirs = ${JSON.stringify(dirs)};
    let mcb = function(err?: NodeJS.ErrnoException): void {
      if (err && err.code !== 'EEXIST') throw err;
      nextDir++;
      if (nextDir === dirs.length) {
        __fixturesAddFiles();
      } else {
        fs.mkdir(dirs[nextDir],mcb);
      }
    };
    let fcb = function(p: string, writtenData: string) {
      return function(err?: NodeJS.ErrnoException) {
        if (err) throw err;
        fs.readFile(p, {encoding:"base64"}, function(err: NodeJS.ErrnoException, readData: string) {
          if (err) throw err;
          if (writtenData != readData) throw new Error('Read data for '+p+' does not match written data:\\n'+readData+'\\n!=\\n'+writtenData);
        });
      };
    };

    let __fixturesAddFiles = function() {

  `);
files.forEach((file) => {
开发者ID:diegolameira,项目名称:codesandbox-client,代码行数:32,代码来源:make_fixture_loader.ts

示例7: stdout

 function stdout(str: any, arg2?: any, arg3?: any): boolean { fs.writeSync(outfile, str); return true; };
开发者ID:altoids,项目名称:doppio,代码行数:1,代码来源:test_runner.ts

示例8: write

 write(data: Buffer) {
   fs.writeSync(this.fd, data, 0, data.length, null /* write from current pos */);
 }
开发者ID:pxpeterxu,项目名称:xar-js,代码行数:3,代码来源:io.ts

示例9: create

 create(text) {
     let tempFile = temp.openSync({suffix: '.py'});
     fs.writeSync(tempFile.fd, text);
     fs.closeSync(tempFile.fd);
     return new TempFileWrapper(tempFile);
 }
开发者ID:pchomik,项目名称:linter-python,代码行数:6,代码来源:util.ts

示例10: getNodeSystem


//.........这里部分代码省略.........
                function visitDirectory(path: string) {
                    let files = _fs.readdirSync(path || ".").sort();
                    let directories: string[] = [];
                    for (let current of files) {
                        let name = combinePaths(path, current);
                        if (!contains(exclude, getCanonicalPath(name))) {
                            let stat = _fs.statSync(name);
                            if (stat.isFile()) {
                                if (!extension || fileExtensionIs(name, extension)) {
                                    result.push(name);
                                }
                            }
                            else if (stat.isDirectory()) {
                                directories.push(name);
                            }
                        }
                    }
                    for (let current of directories) {
                        visitDirectory(current);
                    }
                }
            }

            return {
                args: process.argv.slice(2),
                newLine: _os.EOL,
                useCaseSensitiveFileNames: useCaseSensitiveFileNames,
                write(s: string): void {
                    const buffer = new Buffer(s, "utf8");
                    let offset = 0;
                    let toWrite: number = buffer.length;
                    let written = 0;
                    // 1 is a standard descriptor for stdout
                    while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) {
                        offset += written;
                        toWrite -= written;
                    }
                },
                readFile,
                writeFile,
                watchFile: (fileName, callback) => {
                    // Node 4.0 stablized the `fs.watch` function on Windows which avoids polling
                    // and is more efficient than `fs.watchFile` (ref: https://github.com/nodejs/node/pull/2649
                    // and https://github.com/Microsoft/TypeScript/issues/4643), therefore
                    // if the current node.js version is newer than 4, use `fs.watch` instead.
                    if (isNode4OrLater()) {
                        // Note: in node the callback of fs.watch is given only the relative file name as a parameter
                        return _fs.watch(fileName, (eventName: string, relativeFileName: string) => callback(fileName));
                    }

                    let watchedFile = watchedFileSet.addFile(fileName, callback);
                    return {
                        close: () => watchedFileSet.removeFile(watchedFile)
                    };
                },
                watchDirectory: (path, callback, recursive) => {
                    // Node 4.0 `fs.watch` function supports the "recursive" option on both OSX and Windows
                    // (ref: https://github.com/nodejs/node/pull/2649 and https://github.com/Microsoft/TypeScript/issues/4643)
                    return _fs.watch(
                        path,
                        { persisten: true, recursive: !!recursive },
                        (eventName: string, relativeFileName: string) => {
                            // In watchDirectory we only care about adding and removing files (when event name is
                            // "rename"); changes made within files are handled by corresponding fileWatchers (when
                            // event name is "change")
                            if (eventName === "rename") {
开发者ID:askaleegame,项目名称:egret-core,代码行数:67,代码来源:sys.ts


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