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