A
A
Alexander Petrov2018-03-26 21:19:20
Node.js
Alexander Petrov, 2018-03-26 21:19:20

How to get archive contents on nodejs?

Guys, please help. The first evening I started learning nodejs out of necessity and got stuck on one question.
I need to unzip the archive and get the contents of the text files inside and then perform some manipulations with the contents. There are no problems with the manipulation, but I don’t understand how to get the content ....
The code below displays the path to the files, but I need to get the content using these paths. How is this possible to do? Or maybe you need to use not unzip, but something else? It’s just that most plugins just do archiving and unzipping files, and I can’t find information on what to put in a variable ...

var fs = require('fs')
var unzip = require('unzip')
var path = require('path')

fs.createReadStream('6.zip')
  .pipe(unzip.Parse())
  .on('entry', function (entry) {

    var fileName = entry.path
    var type = entry.type

    console.log(fileName);

  })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Epifanov, 2018-03-26
@Mirkom63

you can read the contents of the resulting file using fs.readFile or fs.readFileSync
documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question