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

TypeScript fs.WriteStream类代码示例

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

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



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

示例1: downloadWrite

export function downloadWrite(incomingMessage:IncomingMessage, user:IUser) {
    const fullPath2Write = getDownloadFullPath(user.name);
    let file:WriteStream = fs.createWriteStream(fullPath2Write);
    incomingMessage.pipe(file);
    file.on('finish', function () {
        const ONE_K = 1024 * 1024;
        if (file.bytesWritten < ONE_K) {
            fs.unlinkSync(fullPath2Write);
        }
        file.close();
        console.log(`下载任务结束: [${user.name}]`);
        user.$isDownloading = false;
    });
}
开发者ID:jf3096,项目名称:bilibili-live-video-noty,代码行数:14,代码来源:fileSteam.ts


示例2: writeInterface

function writeInterface(stream: WriteStream, interf: Interface, name: string) {
    stream.write(`export interface ${name}Interface {\n`);
    if (!interf.hasPrimaryKey) {
        stream.write(`    id?: number; // auto generated property\n`);
    }
    if (interf.createdAt) {
        stream.write(`    ${interf.createdAt}?: Date; // auto generated property\n`);
    }
    if (interf.updatedAt) {
        stream.write(`    ${interf.updatedAt}?: Date; // auto generated property\n`);
    }
    _.forEach(interf.properties, (prop) => {
        var typename = tsTypeToString(prop.tsType, prop.option.associated !== null);
        if (prop.option.associated === null) {
            stream.write(`    ${prop.name}?: ${typename};\n`);
        }
        else {
            stream.write(`    ${prop.name}Id?: number;\n`);
        }
    });
    stream.write("}\n\n");
}
开发者ID:Perlmint,项目名称:TypedSequelize,代码行数:22,代码来源:writer.ts


示例3: writeModelDef

function writeModelDef(stream: WriteStream, interf: Interface, name: string) {
    stream.write(`export interface ${name}Instance extends sequelize.Instance<${name}Interface>, ${name}Interface {`);
    _.forEach(interf.relationships, (rel) => {
        const capitalizedName = _.upperFirst(rel.name);
        const typeName = rel.targetName + "Interface";
        switch(rel.type) {
        case RelationshipType.OneToMany:
            stream.write(`
  get${capitalizedName}(): Promise<${typeName}[]>;
  set${capitalizedName}(vals: ${typeName}[]): Promise<${typeName}[]>;
  remove${capitalizedName}(val: ${typeName}): Promise<void>;
  add${capitalizedName}(val: ${typeName}): Promise<void>;`);
            break;
        case RelationshipType.ManyToOne:
            stream.write(`
  get${capitalizedName}(): Promise<${typeName}>;
  set${capitalizedName}(vals: ${typeName}): Promise<${typeName}>;`);
            break;
        }
    });
    stream.write("\n}\n\n");
    stream.write(`interface ${name}Model extends sequelize.Model<${name}Instance, ${name}Interface> {}\n\n`);
    stream.write(`var ${name}Initialized: boolean = false;\n`);
    stream.write(`export var ${name}: ${name}Model;\n`);
    stream.write(`export function init${name}(seq: sequelize.Sequelize): ${name}Model {
  if (${name}Initialized) {
    return ${name};
  }

`);
    stream.write(`  ${name} = <${name}Model>seq.define<${name}Instance, ${name}Interface>('${name}', {\n`);
    stream.write(
        _.filter(_.map(interf.properties, (prop) => makeProperty(prop))).join(",\n"));
    stream.write("  }, {");
    stream.write("\n");
    stream.write("    indexes: [\n");
    stream.write(
        _.map(interf.indexes, (index) => {
            const fields = index.fields.map((d) => `"${d}"`).join(", ");
            return `      {
        fields: [${fields}]
      }`;
        }).join(",\n")
    );
    stream.write("    ]");
    stream.write("  });\n");
    _.forEach(interf.relationships, (rel) => {
        let moduleName = "";
        if (rel.targetModule != undefined) {
            moduleName = `require('${rel.targetModule}_models').`;
        }
        stream.write(`
  // for setup relation. can't use import in funcion scope
  var ${rel.targetName} = ${moduleName}init${rel.targetName}(seq);`);
        switch (rel.type) {
        case RelationshipType.OneToMany:
            stream.write(`
  ${name}.hasMany(${rel.targetName}, {as: '${rel.name}'});`);
            break;
        case RelationshipType.ManyToOne:
            stream.write(`
  ${name}.belongsTo(${rel.targetName}, {as: '${rel.name}'});`);
        }
    });
    stream.write(`

  ${name}Initialized = true;
  return ${name};
}

`);
}
开发者ID:Perlmint,项目名称:TypedSequelize,代码行数:72,代码来源:writer.ts


示例4: tsTypeToString

 _.forEach(interf.properties, (prop) => {
     var typename = tsTypeToString(prop.tsType, prop.option.associated !== null);
     if (prop.option.associated === null) {
         stream.write(`    ${prop.name}?: ${typename};\n`);
     }
     else {
         stream.write(`    ${prop.name}Id?: number;\n`);
     }
 });
开发者ID:Perlmint,项目名称:TypedSequelize,代码行数:9,代码来源:writer.ts


示例5: switch

   _.forEach(interf.relationships, (rel) => {
       const capitalizedName = _.upperFirst(rel.name);
       const typeName = rel.targetName + "Interface";
       switch(rel.type) {
       case RelationshipType.OneToMany:
           stream.write(`
 get${capitalizedName}(): Promise<${typeName}[]>;
 set${capitalizedName}(vals: ${typeName}[]): Promise<${typeName}[]>;
 remove${capitalizedName}(val: ${typeName}): Promise<void>;
 add${capitalizedName}(val: ${typeName}): Promise<void>;`);
           break;
       case RelationshipType.ManyToOne:
           stream.write(`
 get${capitalizedName}(): Promise<${typeName}>;
 set${capitalizedName}(vals: ${typeName}): Promise<${typeName}>;`);
           break;
       }
   });
开发者ID:Perlmint,项目名称:TypedSequelize,代码行数:18,代码来源:writer.ts


示例6: relative

 _.forEach(info.imports, (items: string[], moduleName: string) => {
     if (moduleName[0] === ".") {
         moduleName = relative(writeInfo.outDir,
                               join(dirname(writeInfo.srcPath), moduleName))
             .replace(new RegExp("\\\\", "g"), "/");
     }
     const joinedItems = _.uniq(items).join(", ");
     stream.write(`import { ${joinedItems} } from '${moduleName}';\n`);
 });
开发者ID:Perlmint,项目名称:TypedSequelize,代码行数:9,代码来源:writer.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs-copy-file-sync.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs.Stats类代码示例发布时间: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