0

I'm trying to make some code which makes server unzip requested file by using nodejs(express)...

app.post('/unzip', function(req, res) {

    //Get User Information

    var id = req.body.id;


    //Get ZIP Information

    var rendering_ready_file_unzip = req.body.filename + '.zip';
    var rendering_ready_file_unzip_nonext = req.body.filename;

    //Extract zip

    var extract = require('extract-zip');

    var unzip_route = path.join(__dirname, '../unzip/' + "id" + '/' + date + '/');;

    extract(path.join(__dirname, '../upload/' + rendering_ready_file_unzip), {dir: unzip_route}, function (err) {
        if (err) {
            console.log(err);
        }
        res.end();
    });}

It works... but other languages like Korean damaged after unzip.. So I want to know about unzip-modules which can designate encoding type.

Do you know it?

nate
  • 13
  • 1
  • 5

1 Answers1

-1

The problem may not be with the module. It helps to reduce troubled code to the minimum, and in this case that might be the following:

const path = require('path');
const extract = require('extract-zip');

const file_unzip = 'test.zip';

extract(path.join(__dirname, file_unzip), {dir: __dirname}, function (err) {
  if (err) {
    console.log(err);
  }
});

After putting that in index.js and installing extract-unzip, a same-directory test case is possible in bash. Echo Korean characters to a file and make sure they are there:

$echo 안녕하세요>test
$cat test
안녕하세요

Zip the file, remove the original and make sure it is gone:

$zip test.zip test
adding: test (stored 0%)
$rm test
$ls test*
test.zip

Run the script and see that the file has been extracted and contains the same characters:

$node index.js
$ls test*
test  test.zip
$cat test
안녕하세요

I got the same results with characters from several other languages. So at least in this setup, the module unzips without changing the characters in the inner files. Try running the same tests on your system, and take a good look at what happens prior to unzipping. Problems could lurk in how the files are generated, encoded, zipped, or uploaded. Investigate one step at a time.

MBer
  • 2,218
  • 20
  • 34