diff --git a/package.json b/package.json index 5c83556..191a7b6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "public-google-sheets-parser", - "version": "1.2.3", + "version": "1.2.4", "description": "Get JSONArray from public google sheets with using only spreadsheetId", "scripts": { "build:dist": "npx babel ./src/index.js --out-file ./dist/index.js", diff --git a/src/fetch.js b/src/fetch.js index 8b3f9cb..42b36fa 100644 --- a/src/fetch.js +++ b/src/fetch.js @@ -3,10 +3,18 @@ const https = require('https') const nodeFetch = async (url) => { return new Promise((resolve, reject) => { const req = https.request(url, (res) => { - res.on('data', (data) => { - if (!String(data).startsWith('/*O_o*/')) return resolve(null) + const body = [] + let isStarted = false - const response = { ok: true, text: () => String(data) } + res.on('data', (chunk) => { + if (!isStarted && !String(chunk).startsWith('/*O_o*/')) return resolve(null) + isStarted = true + + body.push(chunk) + }) + + res.on('end', () => { + const response = { ok: true, text: () => Buffer.concat(body).toString() } resolve(response) }) })