Last active
July 15, 2019 19:52
-
-
Save alexismp/5f1fe020a88717d9ded41f0af2a506f2 to your computer and use it in GitHub Desktop.
csv2sheet readCSVContent (assumes CSV content, no parsing)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function readCSVContent(sheetsAPI, file, sheetName) { | |
return new Promise((resolve, reject) => { | |
const storage = new Storage(); | |
let fileContents = new Buffer(''); | |
let rows = []; | |
storage | |
.bucket(file.bucket) | |
.file(file.name) | |
.createReadStream() | |
.on("error", function(err) { | |
reject("The Storage API returned an error: " + err); | |
}) | |
.on("data", function(chunk) { | |
fileContents = Buffer.concat([fileContents, chunk]); | |
}) | |
.on("end", function() { | |
let content = fileContents.toString('utf8'); | |
console.log("CSV content read as string : " + content ); | |
resolve(content); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment