库文件的入口文件和过程文件的生成
431601
function libPkgPre() {
    var obj = {
            name: '',
            version: config.version,
            spm: config.spm
        },
        libCon, libsjs = '',
        key,
        libDir = dist_dir.js + '';
    obj.spm.main = 'libs.js';
    obj.spm.buildArgs = '--idleading {{name}} --include all';

    libCon = JSON.stringify(obj);
    fs.renameSync('package.json', 'package_bak.json');
    fs.writeFileSync('package.json', libCon); //生成库文件pkg配置
    var packages = [];
    for (key in obj.spm.dependencies) {
        if (obj.spm.inside[key]) {
            packages.push(obj.spm.inside[key]);
        } else {
            packages.push(key);
        }
    }
    for (var i = 0; i < packages.length; i++) {
        libsjs += "require('" + packages[i] + "');";
    }


    fs.writeFileSync('libs.js', libsjs); //写入口文件
    return libDir;
}
809891
function () {
      var data = dox.parseComments(convert._buffer.toString(), { raw: true });
      var mdApi = _generateMdApi(data, opts);

      // Just use MD straight up if no destination insertion.
      var contents = opts.src ?
        convert.insertTextStream(mdApi + "\n") :
        new Buffer(mdApi);

      this.emit("data", new gutil.File({
        path: opts.name,
        contents: contents
      }));

      this.emit("end");
    }
1193407
function createOutputFolder(next) {
    var defPath         = path.join(getConfig('output.folder'), 'definition-files'),
        defPathCustom   = path.join(getConfig('output.folder'), 'definition-files-custom');

    fs.remove(defPath, function (err) {
        if (err) { next(err); }
        fs.createFile(path.join(defPath, '_Dont_add_or_edit_any_files'), function (err) {
            if (err) { next(err); }
            fs.mkdirs(defPathCustom, function (err) {
                if (err) { next(err); }
                next(null);
            });
        });
    });
}
687280
function getPublishFile(selectedFile) {
        console.log('你需要发布文件如下：');
        
        var files = [];
        selectedFile.forEach(function(file, idx) {
            console.log('  [' + (idx + 1) + ']' + file);
            files.push(file);
        });
        
        prepareBatchPubFiles(awpConfig, pubConfig, files);

    }
1192987
function wrapper(my) {

  var start = process.hrtime();
  var c = 0, e = 0;
  var doit = [];
  var stream = startline({
    file: my.filename,
    encoding: 'utf8',
  });

  // options
  var open = ansi.green.open;
  var close = ansi.green.close;
  if (my.url) {
    doit
        .push([
          input.url,
          [ Object.create(null), 'url' ],
          [ output.url,
            [ open + 'ROUTE', 'METHOD', 'STATUS', 'COUNTER', close ] ] ]);
  }
  if (my.ip) {
    doit.push([ input.cc, [ Object.create(null), 'ip' ],
      [ output.ip, [ open + 'IP', 'COUNTER' + close ] ] ]);
  }
  if (my.response) {
    doit.push([ input.avg, [ {
      what: 0,
      total: 0,
      max: 0,
      min: 10000
    }, 'response' ], [ output.avg, [ open + 'RESPONSE', 'MS' + close ] ] ]);
  }
  if (my.pid) {
    doit.push([ input.cc, [ Object.create(null), 'pid' ],
      [ output.cc, [ open + 'PID' + close ] ] ]);
  }
  if (my.bytesReq) {
    doit.push([ input.avg, [ {
      what: 0,
      total: 0,
      max: 0,
      min: 10000
    }, 'bytesReq' ],
      [ output.avg, [ open + 'BYTES REQUESTED', 'BYTE' + close ] ] ]);
  }
  if (my.bytesRes) {
    doit.push([ input.avg, [ {
      what: 0,
      total: 0,
      max: 0,
      min: 10000
    }, 'bytesRes' ], [ output.avg, [ open + 'BYTES SENT', 'BYTE' + close ] ] ]);
  }
  if (my.referrer) {
    doit.push([ input.cc, [ Object.create(null), 'referrer' ],
      [ output.cc, [ open + 'REFERRER' + close ] ] ]);
  }
  if (my.auth) {
    doit.push([ input.cc, [ Object.create(null), 'auth' ],
      [ output.cc, [ open + 'USER ATHENTICATION' + close ] ] ]);
  }
  if (my.agent) {
    doit.push([ input.cc, [ Object.create(null), 'agent' ],
      [ output.cc, [ open + 'USER-AGENT' + close ] ] ]);
  }
  if (my.version) {
    doit.push([ input.cc, [ Object.create(null), 'version' ],
      [ output.cc, [ open + 'HTTP VERSION' + close ] ] ]);
  }
  if (my.level) {
    doit.push([ input.cc, [ Object.create(null), 'level' ],
      [ output.cc, [ open + 'LOG LEVEL' + close ] ] ]);
  }
  if (my.message) {
    doit.push([ input.cc, [ Object.create(null), 'message' ],
      [ output.cc, [ open + 'LOG MESSAGE' + close ] ] ]);
  }
  if (my.timestamp) {
    doit.push([ input.cc, [ Object.create(null), 'timestamp' ],
      [ output.cc, [ open + 'LOG TIMESTAMP' + close ] ] ]);
  }

  // go
  if (my.search) {
    doit = [];

    stream.on('line', function(lines) {

      var s = lines.match(my.search);
      if (s) {
        var line = lines.replace(my.search, ansi.red.open + s[0]
          + ansi.red.close + ansi.gray.open);
        // console.log(s)
        doit.push([ 'line ' + c, ansi.gray.open + line + ansi.gray.close ]);
      }
      ++c;
    });
    stream.on('close', function() {

      if (doit.length === 0) {
        console.log('Not found');
      }
      console.log(table(doit));
    });

  }

  stream.on('line', function(lines) {

    ++c;
    try {
      var line = JSON.parse(lines);
      for (var i = 0, ii = doit.length; i < ii; ++i) {
        var params = doit[i][1];
        params[0] = doit[i][0](line, params);
      }
    } catch (err) {
      ++e;
    }
  });

  stream.on('close', function() {

    var out = [];
    var csv = [];
    for (var i = 0, ii = doit.length; i < ii; ++i) {
      var buff = doit[i][2][0](doit[i][1], doit[i][2][1]);
      for (var b = 0, bb = buff.length; b < bb; ++b) {
        out.push(buff[b]);
      }
    }

    var consol = out.slice();
    if (my.report) {
      csv.push([ ansi.yellow.open + 'REPORT' + ansi.yellow.close ], [
        'line parsed', ansi.underline.open + c + ansi.underline.close ]);
      consol.push(csv[0]);
      consol.push(csv[1]);
      if (e > 0) {
        csv.push([ ansi.red.open + 'line error', e + ansi.red.close ]);
        consol.push(csv[2]);
      }
      var diff = process.hrtime(start);
      diff = ((diff[0] * 1e9 + diff[1]) / 1000000).toFixed(3) + ' ms';
      csv.push([ 'time elapsed',
        ansi.underline.open + diff + ansi.underline.close ]);
      consol.push(csv[csv.length - 1]);
    }

    // print
    if (my.csv) { // file
      var to_csv = require('./lib/csv.js');
      console.log(table(csv, {
        align: [ 'l', 'r' ],
        stringLength: function(s) {

          return s.replace(re, '').length;
        }
      }));
      to_csv(String(my.csv), out);
    } else { // console
      console.log(table(consol, {
        align: [ 'l', 'r' ],
        stringLength: function(s) {

          return s.replace(re, '').length;
        }
      }));
    }
  });

  return my;
}
817205
function watchOnFile(file, callback) {
  let lastIndex = 0
  let timer

  function read() {
    const stat = fs.statSync(file)

    if (stat.size !== lastIndex) {
      const fd = fs.openSync(file, 'r')
      const buffer = Buffer.alloc(stat.size - lastIndex)

      try {
        fs.readSync(fd, buffer, lastIndex, stat.size - lastIndex)
        const content = buffer.toString('utf8')
        lastIndex = stat.size

        callback(content)
      } catch (error) {
        // 从头读起
        lastIndex = 0
      }
    }

    timer = setTimeout(read, 200)
  }

  read()
  return function() {
    clearTimeout(timer)
  }
}
1133829
function(url, filepath, fn){
        // 提交请求
        try{
            fs.createReadStream(filepath).pipe(request.post(url, fn))
        }
        catch(e){ fn(e) }
    }
1303424
def download(input, filename, format='sdf', overwrite=False, resolvers=None, **kwargs):
    
    kwargs['format'] = format
    if resolvers:
        kwargs['resolver'] = ",".join(resolvers)
    url = API_BASE+'/%s/file?%s' % (urlquote(input), urlencode(kwargs))
    try:
        servefile = urlopen(url)
        if not overwrite and os.path.isfile(filename):
            raise IOError("%s already exists. Use 'overwrite=True' to overwrite it." % filename)
        file = open(filename, "w")
        file.write(servefile.read())
        file.close()
    except urllib.error.HTTPError:
        # TODO: Proper handling of 404, for now just does nothing
        pass
130532
function writeFile(input, output, type) {
    var json    = readFile(input),
        content = getContent(json, type);

    fs.writeFile(output, content, function (err) {
        if (err) {
            throw err;
        }

        console.log('The file "' + output + '" was written successfully!');
    });
}
366367
def generate
      begin
        # 删除要输出的路径
        FileUtils.mkdir_p(self.tmp_deploy_path)

        ::Docwu::Utils.cp_r("#{plain_path('/assets')}", "#{self.tmp_deploy_path}/assets")

        # 复制静态文件里去
        ::Docwu::Utils.cp_r("#{plain_path('/static')}", "#{self.tmp_deploy_path}/static")

        self.folders.each do |folder|
          folder.generate
        end

        self.topics.each do |topic|
          topic.generate
        end

      rescue Exception => exception
        FileUtils.rm_rf(self.tmp_deploy_path)
        raise "#{exception}"
      else
        FileUtils.rm_rf(self.deploy_path)
        FileUtils.mv(self.tmp_deploy_path, self.deploy_path)
      ensure
      end
    end
1025549
function encodeFileToJson(file) {
    var filePath = file.getPath();
    if (!filePath) {
        return undefined;
    }

    return {
        path: filePath,
        mtime: file.getMTime(),
        type: file.getType()
    };
}
220104
def generate_text_files(in_dir, out_dir, include_header=False):
    
    for cable in cables_from_source(in_dir):
        out = codecs.open(out_dir + '/' + cable.reference_id + '.txt', 'wb', encoding='utf-8')
        out.write(cable_to_text(cable, include_header))
        out.close()
1363338
function downloadFile(url, outputPath) {
	const dir = path.dirname(outputPath);
	if (!fs.existsSync(dir)) {
		fs.mkdirSync(dir);
	}
	return new Promise((resolve, reject) => {
		const file = fs.createWriteStream(outputPath);
		const sendReq = request.get(url);
		sendReq.pipe(file);

		sendReq
		.on("response", (response) => {
			if (response.statusCode !== 200) {
				fs.unlink(outputPath);
				const error = new Error("Response status code was " + response.statusCode + ".");
				console.trace(error);
				reject(error);
			}
		})
		.on("error", (error) => {
			fs.unlink(outputPath);
			console.trace(error);
			reject(error);
		});

		file
		.on("finish", () => {
			file.close(() => {
				resolve();
			});
		})
		.on("error", (error) => {
			fs.unlink(outputPath);
			console.trace(error);
			reject(error);
		});
	});
}
398156
function combineFileContent(pkg, toMergeFiles, context) {
    var content = '';
    var has = [];
    var isPackBundles = !! pkg.isPackBundles;
    toMergeFiles.forEach(function (file) {
        has.push(file.id);
        if(isPackBundles){
            if(file.packBundlesTo){
                fis.log.error('file [%s] has packBundlesTo[%s],can not packBundles more than once!',file.id,pkg.id);
                return;
            }
            file.packBundlesTo = pkg.subpath;
        }
        // 把要合并的文件的依赖信息添加到打包文件里
        addDependenceResource(pkg, 'addLink', file.links,context);
        addDependenceResource(pkg, 'addRequire', file.requires,context);
        addDependenceResource(pkg, 'addAsyncRequire', file.asyncs,context);

        var c;
        if(!isPackBundles && file.packBundlesTo){
            //已经合并在Bundles里面的模块不用打包到pkg里面，只需要pathmap里设置为Bundles文件的moduleId即可
            c = '';
        }else{
            c = file.getContent();
        }

        
       /* if (c && file.isCssLike && file !== pkg) {
            c = updateCSSContentUrl(c, file, pkg, context);
        }*/

        if (c) {
            if (file.isCssLike) {
                c = c.replace(CSS_CHARSET_REGEXP, '');
            }

            /**
             * @event pack:file 触发打包事件
             */
            fis.emit('pack:file', {
                file: file,
                content: c,
                pkg: pkg
            });

            content += c + '\n';
        }
    });

    return {
        content: content,
        has: has
    };
}
1211310
def _create_sample_file(data, out_dir):
    """"""
    sample_file = os.path.join(out_dir, "sample_file.txt")
    with open(sample_file, 'w') as outh:
        for sample in data:
            outh.write(sample[0]["clean_fastq"] + "\n")
    return sample_file
932496
function write(file, data) {
  writeFileSync(file, data);

  console.log(
    `✓ ${relative(__dirname + "/../", file)} (${bytes(statSync(file).size)})`
  );
}
718347
@Override
	protected void generateFileHeader(QualifiedName qualifiedName, ExtraLanguageAppendable appendable,
			IExtraLanguageGeneratorContext context) {
		appendable.append(PYTHON_FILE_HEADER);
		appendable.newLine();
		appendable.append(getGenerationComment(context));
		appendable.newLine().newLine();
	}