本文整理匯總了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`);
});