Javascript Exec из Curl, переданных в tar Хиты Ошибка - PullRequest
0 голосов
/ 09 апреля 2019

У меня есть команда оболочки, чтобы загрузить и распаковать файл, выполненный из JavaScript.Когда это делается как curl, переданный в tar, иногда происходит сбой:

const child_process = require('child_process');
var cmd = `curl -s ${file} | tar -xj --strip-components=1 --exclude=README.txt -C ${directory}`;
child_process.exec(cmd, function commandCallback(error, stdout, stderr) {
      console.log('done downloading ' + type + ' bundle');
      if (error) {
        console.error('error downloading ' + type + ' bundle: ' + error);
        console.log(stderr);
      }

с ошибками типа

Error: Command failed: curl -s https://dist.whosonfirst.org/bundles/whosonfirst-data-locality-latest.tar.bz2 | tar -xj --strip-components=1 --exclude=README.txt -C /mnt/storage-proc2/users/jeremy/pelias_metal/data/whosonfirst    
bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.
bzip2: Inappropriate ioctl for device
        Input file = (stdin), output file = (stdout)

, но если команда выполняется как таковая

var cmd=`wget -q ${file} && tar -xj --strip-components=1 --exclude=README.txt -C ${directory} -f latest.file `;

Тогда все работает нормально.Кто-нибудь знает, что вызывает сбой первой команды?Трубопровод напрямую к tar может сэкономить немного времени и дискового пространства и, следовательно, был бы предпочтительным.

Node.js, очевидно, имеет проблемы с заполнением буферов при длительных загрузках, если флаг -s не передан в curl, ноздесь это не проблема, так как присутствует флаг -s.

edit - похоже, JavaScript не виновник:

jeremyr@w6:~/pelias_metal/whosonfirst$ curl -s https://dist.whosonfirst.org/bundles/whosonfirst-data-postalcode-jp-latest.tar.bz2 | tar -xj --strip-components=1 --exclude=README.txt -C /mnt/data_science/pelias_w6/data/whosonfirst && mv /mnt/data_science/pelias_w6/data/whosonfirst/whosonfirst-data-postalcode-jp-latest.csv /mnt/data_science/pelias_w6/data/whosonfirst/meta 

bzip2: Compressed file ends unexpectedly;
        perhaps it is corrupted?  *Possible* reason follows.

, а также wget -q -O | tar работает -

jeremyr@w6:~/pelias_metal/whosonfirst$ wget -q -O - https://dist.whosonfirst.org/bundles/whosonfirst-data-postalcode-jp-latest.tar.bz2|tar -xj --strip-components=1 --exclude=README.txt -C /mnt/data_science/pelias_w6/data/whosonfirst
jeremyr@w6:~/pelias_metal/whosonfirst$

...