fs-extra#createWriteStream TypeScript Examples
The following examples show how to use
fs-extra#createWriteStream.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AttachmentsFilesService.ts From node-experience with MIT License | 6 votes |
static async getTempFilesAttachments(emailNotification: EmailNotification): Promise<IFilesAttachments[]>
{
const filesystem = FilesystemFactory.create();
emailNotification.tempFilesAttachments = await Promise.all(emailNotification.attachedFiles.map(async(_file) =>
{
const stream = await filesystem.downloadStreamFile(_file);
const fileName = `${_file.originalName}.${_file.extension}`;
const uqFileName = `${_file.name}.${_file.extension}`;
const tempDir = PATH.join(`${__dirname}/../../../temp`);
const dirName = PATH.join(`${tempDir}/${uqFileName}`);
// eslint-disable-next-line no-unused-expressions
!existsSync(tempDir) && mkdirSync(tempDir);
void await writeFile(dirName, '01011');
const ws = createWriteStream(dirName);
stream.pipe(ws);
return {
filename: fileName,
path:dirName
};
}));
return emailNotification.tempFilesAttachments;
}
Example #2
Source File: dev.ts From gdmod with MIT License | 6 votes |
async function buildMod() {
const zip = new JSZip();
// Copy resources
await Promise.all(
(
await readdir("./resources")
).map(async (file) =>
zip.file("resources/" + file, await readFile("./resources/" + file))
)
);
// Read manifests
const [gdmod, resources, bundle] = await Promise.all([
await readFile("./data/GDMod.json"),
await readFile("./data/resources.json"),
await readFile("./dist/bundle.js"),
]);
return new Promise(async (resolve, reject) =>
zip
.file("data/GDMod.json", gdmod)
.file("data/resources.json", resources)
.file("data/includes.json", `["bundle.js"]`)
.file("code/bundle.js", bundle)
.generateNodeStream()
.pipe(createWriteStream("./dist/mod.zip"))
.once("finish", resolve)
.once("error", reject)
);
}
Example #3
Source File: io.ts From DefinitelyTyped-tools with MIT License | 5 votes |
export function writeTgz(inputDirectory: string, outFileName: string): Promise<void> {
return new Promise<void>((resolve, reject) => {
resolve(streamDone(createTgz(inputDirectory, reject).pipe(createWriteStream(outFileName))));
});
}
Example #4
Source File: index.ts From cli with MIT License | 5 votes |
private async makeZip(sourceDirection: string, targetFileName: string) {
let ignore = [];
if (this.core.service?.experimentalFeatures?.removeUselessFiles) {
this.core.cli.log(' - Experimental Feature RemoveUselessFiles');
ignore = uselessFilesMatch;
}
const globbyMatched = ['**'];
const npmClient = this.getNPMClient();
if (npmClient?.startsWith('pnpm')) {
globbyMatched.push('**/.pnpm/**');
}
const fileList = await globby(globbyMatched, {
onlyFiles: false,
followSymbolicLinks: false,
cwd: sourceDirection,
ignore,
});
const zip = new JSZip();
const isWindows = platform() === 'win32';
for (const fileName of fileList) {
const absPath = join(sourceDirection, fileName);
const stats = await lstat(absPath);
if (stats.isDirectory()) {
zip.folder(fileName);
} else if (stats.isSymbolicLink()) {
let link = await readlink(absPath);
if (isWindows) {
link = relative(dirname(absPath), link).replace(/\\/g, '/');
}
zip.file(fileName, link, {
binary: false,
createFolders: true,
unixPermissions: stats.mode,
});
} else if (stats.isFile()) {
const fileData = await readFile(absPath);
zip.file(fileName, fileData, {
binary: true,
createFolders: true,
unixPermissions: stats.mode,
});
}
}
await new Promise((res, rej) => {
zip
.generateNodeStream({
platform: 'UNIX',
compression: 'DEFLATE',
compressionOptions: {
level: 6,
},
})
.pipe(createWriteStream(targetFileName))
.once('finish', res)
.once('error', rej);
});
}