sax
을 참조하십시오. isaacs가 개발했습니다.
이 코드를 테스트하지는 않았지만이 줄을 따라 뭔가를 작성합니다.
var Promise = Promise || require('es6-promise').Promise
, thr = require('through2')
, createReadStream = require('fs').createReadStream
, createUnzip = require('zlib').createUnzip
, createParser = require('sax').createStream
;
function processXml (filename) {
return new Promise(function(resolve, reject){
var unzip = createUnzip()
, xmlParser = createParser()
;
xmlParser.on('opentag', function(node){
// do stuff with the node
})
xmlParser.on('attribute', function(node){
// do more stuff with attr
})
// instead of rejecting, you may handle the error instead.
xmlParser.on('error', reject)
xmlParser.on('end', resolve)
createReadStream(filename)
.pipe(unzip)
.pipe(xmlParser)
.pipe(thr(function(chunk, enc, next){
// as soon xmlParser is done with a node, it passes down stream.
// change the chunk if you wish
next(null, newerChunk)
}))
rl = readline.createInterface({
input: unzip
, ouput: xmlParser
})
})
}
processXml('large.xml.gz').then(function(){
console.log('done')
})
.catch(function(err){
// handle error.
})
나는 그
는 네이티브 확장을 작성하고 C++ 라이브러리를 사용하여 생각 해 봤나 도움이되기를 바랍니다? 파일 크기가 클 경우이 옵션이 가장 좋습니다 ... – ChrisCM
잘 모르겠 음 C++ tbh. 현재 파일을 압축 해제 한 다음 마감일을 사용하여 작업을 수행 할 수 있지만 프로덕션 환경으로 롤백하면 사용 권한이 잠겨 로그 폴더의 내용을 변경할 수없고 읽기만 가능합니다. –
sudo를 사용하여 노드 프로세스를 실행 해보십시오. – ChrisCM