Skip to content

Commit

Permalink
update nodeFecth implementation
Browse files Browse the repository at this point in the history
resolves #10
  • Loading branch information
fureweb-com committed Mar 16, 2021
1 parent 28376d4 commit 84e69e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
14 changes: 11 additions & 3 deletions src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})
Expand Down

0 comments on commit 84e69e5

Please sign in to comment.