當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。