本文整理汇总了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;
});
}
示例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");
}
示例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};
}
`);
}
示例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`);
}
});
示例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;
}
});
示例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`);
});