This is a follow-up to this thread.
I am trying to use the code provided by @July.Tech there, but I keep getting unknown compression method error or incorrect header check error. The error came up when either of two different gzip methods were used to create the compressed file, so I would think the file is correctly gzipped.
Any suggestions? (My input file is gzipped so I cannot use Utilities.unzip().)
Here is the entire code:
reports_folder_id = 'xxxxx'; //id of folder where gzipped csv reports are saved
report_name = 'xxxxxx.gz'; // name of gzipped CSV file
function importData() {
var fSource = DriveApp.getFolderById(reports_folder_id);
var fi = fSource.getFilesByName(report_name); // latest report file
eval(UrlFetchApp.fetch('https://cdn.rawgit.com/nodeca/pako/master/dist/pako.js').getContentText());
if ( fi.hasNext() ) { // proceed if report_name file exists in the reports folder
var file = fi.next();
var charData = file.getBlob().getDataAsString(); // same error if .getBytes() is used
var binData = [];
for (var i = 0; i < charData.length; i++) {
binData.push(charData[i] < 0 ? charData[i] + 256 : charData[i]);
}
var data = pako.ungzip(binData); // I get same error for pako.inflate(binData);
var decoded = '';
for (var i = 0; i < data.length; i++) {
decoded += String.fromCharCode(data[i]);
}
}
}
If no suggestion for fixing the above, any ideas on how to ungzip a gDrive file programatically?
Thanks.
As of January 19, 2018 (see release notes) Apps Script now supports gzip compression accessible using the following
Utilities
methods:gzip(blob)
ungzip(blob)
You need to find out if pako supports gzip compression. If not, you should look for another compression package that supports gzip.
Running the supplied example code indeed results in unknown compression method error in my environment as well.
Try changing
To
So that is
Try running this script on a subset of your original "GlicemiaMisurazioni.csv.gz" file: https://drive.google.com/file/d/0B8geUNXmd4J2YzJoemFLMnBTbVU/view?usp=sharing
(I truncated the original csv to 32 rows to speed up execution for the sake of test – the original takes way too long to run)
Checking the logs shows that the uncompressing worked: