本文整理汇总了TypeScript中fs-extra.createReadStream函数的典型用法代码示例。如果您正苦于以下问题:TypeScript createReadStream函数的具体用法?TypeScript createReadStream怎么用?TypeScript createReadStream使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了createReadStream函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addTranslations
public async addTranslations(
file: string,
language: string,
documentPath: string,
options: any
) {
const formData = new FormData()
formData.append('file', fs.createReadStream(file))
formData.append('document_path', documentPath)
formData.append('document_format', this.config.format)
formData.append('language', language)
let url = `${this.apiUrl}/add-translations`
if (!options.write) url = `${url}/peek`
if (options['merge-type']) {
formData.append('merge_type', options['merge-type'])
}
const response = await fetch(url, {
body: formData,
headers: this.authorizationHeader(),
method: 'POST'
})
return this.handleResponse(response, options, OperationName.AddTranslation)
}
示例2: callback
database.save(DEFAULT_USER, defaultUser, (err, result) => {
if (err) {
return callback(err);
}
var attachmentData = {
'Content-Type': 'image/' + ext,
name: 'user'
};
var readstream = fse.createReadStream(originalPicture);
var writestream = database.saveAttachment(result, attachmentData, (err, result)=> {
if (err) {
return callback(err);
}
var attachmentData = {
'Content-Type': 'image/' + ext,
name: 'userThumb'
};
var readstream = fse.createReadStream(thumbnailPicture);
var writestream = database.saveAttachment(result, attachmentData, callback);
// stream thumbnail
readstream.pipe(writestream);
});
// stream picture
readstream.pipe(writestream);
});
示例3: resolve
new Promise<string>((resolve, reject) => {
let data = ''
const stream = fs.createReadStream(file, { encoding: 'utf-8' })
stream.on('data', chunk => (data += chunk))
stream.on('end', () => resolve(data))
stream.on('error', err => reject(err))
})
示例4:
return new Promise<void>((resolve, reject) => {
const rs = fs.createReadStream(from);
const ws = fs.createWriteStream(to);
rs.on('error', reject);
ws.on('error', reject);
ws.on('close', resolve);
rs.pipe(ws);
});
示例5: Promise
.then(() => new Promise((resolve, reject) => {
const rd = fs.createReadStream(from);
rd.on('error', (err: Error) => reject(err));
const wr = fs.createWriteStream(to);
wr.on('error', (err: Error) => reject(err));
wr.on('close', () => resolve());
rd.pipe(wr);
}));
示例6: process
function process(response: express.Response, filePath: string) {
let chapterPages = [] as shared.IApiChapter;
fs.createReadStream(filePath)
.pipe(unzipper.Parse())
.on('close', () => response.send(chapterPages))
.on('entry', (entry: unzipper.Entry) => {
chapterPages.push(entry.path);
entry.autodrain();
});
}
示例7: resolve
return await new Promise<Buffer>((resolve, reject) => {
const chunks = new Array<Buffer>()
let total = 0
Fs.createReadStream(path, { start, end })
.on('data', (chunk: Buffer) => {
chunks.push(chunk)
total += chunk.length
})
.on('error', reject)
.on('end', () => resolve(Buffer.concat(chunks, total)))
})
示例8: test
test('rewrites long complex file', async (t) => {
const beforeStream = fs.createReadStream(
path.join(__dirname, '../../src/test/goldens/paper-button-demo.html'));
beforeStream.setEncoding('utf8');
const expected = await fs.readFile(
path.join(
__dirname, '../../src/test/goldens/paper-button-demo-expected.html'),
'utf8');
const actualStream = beforeStream.pipe(new HTMLRewriter({}));
t.is(await getStream(actualStream), expected);
});
示例9: Promise
return new Promise((resolve, reject) => {
const writeStream = createWriteStream(destPath);
writeStream.on('error', (err: Error) => {
reject(err);
});
writeStream.on('close', () => {
resolve();
});
createReadStream(srcPath).pipe(writeStream);
});
示例10: process
function process(request: express.Request, response: express.Response, filePath: string) {
fs.createReadStream(filePath)
.pipe(unzipper.Parse())
.on('close', () => {
if (response.headersSent) return;
response.sendStatus(404);
})
.on('entry', (entry: unzipper.Entry) => {
if (entry.path !== request.params.pageName) return entry.autodrain();
response.set('Content-Type', mime.getType(entry.path) || 'application/octet-stream');
return entry.pipe(response);
});
}