本文整理汇总了TypeScript中event-stream.split函数的典型用法代码示例。如果您正苦于以下问题:TypeScript split函数的具体用法?TypeScript split怎么用?TypeScript split使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createReadStream
.pipe(map((file, callback) => {
let variableLine, variableName, defaultValue, multiline;
createReadStream(file.path, { flags: 'r'})
.pipe(split())
.pipe(map((line, callback) => {
if (line.charAt(0) === '$') {
variableLine = line.split(/:(.+)/);
variableName = variableLine[0];
defaultValue = variableLine[1];
// If there is a semicolon then it isn't a multiline value
multiline = line.indexOf(';') > -1 ? false : true;
if (!multiline && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
}
} else if (multiline === true) {
defaultValue += '\n' + line;
// If the line has a semicolon then we've found the end of the value
if (line.indexOf(';') > -1 && line.indexOf('!default') > -1) {
addVariable(variableName, defaultValue, file);
multiline = false;
}
}
callback();
}));
callback();
}).on('end', () => {
示例2: parse_file_line
export function parse_file_line(file_path : string, parse : (line:string)=>void, error : () => void, success : () => void){
let fs = require('fs')
let es = require('event-stream');
let stream = fs.createReadStream(file_path).pipe(es.split()).pipe(
es.mapSync(function(line){
stream.pause();
parse(line);
stream.resume();
}).on('error',function(){
error();
}).on('end',function(){
success();
})
);
}
示例3: require
var crc32 = require("crc-32");
var pgp = require('pg-promise')();
var cn = {
host: 'localhost',
port: 5432,
database: 'Test',
user: 'postgres',
password: 'postgres'
};
var db = pgp(cn);
var currLineNumber = 0;
var fs = require('fs'), util = require('util'), stream = require('stream'), es = require('event-stream');
var s = fs.createReadStream('./Data/words.txt')
.pipe(es.split())
.pipe(es.mapSync(function(line){
s.pause();
var hash = crc32.str(line);
db.none("INSERT INTO \"Words\"(\"Word\", \"Hash\", \"HashSigned\", \"HashInteger\") VALUES(${word}, ${hash}, ${hashSigned}, ${hashInteger})", {
word: line,
hash: numberToHex(hash, 2),
hashSigned: numberToHexSigned(hash, 2),
hashInteger: hash,
}).then(() => {
if(++currLineNumber % 1000 === 0) {
console.info("INSERT ROWS: " + Math.round(currLineNumber / 1000) + "k, latest line: " + line);
}
s.resume();
}).catch((data) => {
示例4:
console.info("--- --- Phase: 3 - Json convert\n");
var packedDictionary: IPackedDictionary = {
rule: {
firstIndex: this.rule.firstIndex,
charCount: this.rule.charCount
},
data: data
};
return JSON.stringify(packedDictionary);
}
}
//var count = 0;
fs.createReadStream(wordsPath).pipe(es.split()).pipe(es.mapSync((line: string) => {
word = line.toLowerCase();
// if(word.indexOf("'") !== -1) {
// count++;
// }
//
// var wordLength = word.length;
//
// if(wordLength > 6) {
// if(word.indexOf("'") > wordLength / 2 && word.lastIndexOf("'") < wordLength - 4) {
// console.info(word);
// }
// }
for(key in dictionaries) {