Skip to content

Instantly share code, notes, and snippets.

@alexismp
Last active July 15, 2019 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexismp/5f1fe020a88717d9ded41f0af2a506f2 to your computer and use it in GitHub Desktop.
Save alexismp/5f1fe020a88717d9ded41f0af2a506f2 to your computer and use it in GitHub Desktop.
csv2sheet readCSVContent (assumes CSV content, no parsing)
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