Skip to content

Commit

Permalink
Revert "fix(gatsby-source-filesystem): fix broken stream with gzipped…
Browse files Browse the repository at this point in the history
… files (#28913)"

This reverts commit 38c0f42
  • Loading branch information
vladar committed Jan 12, 2021
1 parent 38c0f42 commit 7e9ee09
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 413 deletions.
3 changes: 1 addition & 2 deletions packages/gatsby-source-filesystem/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"@babel/cli": "^7.12.1",
"@babel/core": "^7.12.3",
"babel-preset-gatsby-package": "^0.10.0",
"cross-env": "^7.0.3",
"msw": "^0.25.0"
"cross-env": "^7.0.3"
},
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme",
"keywords": [
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ describe(`create-remote-file-node`, () => {
describe(`valid url`, () => {
let uuid = 0

const setup = (args = {}, response = { statusCode: 200 }) => {
const setup = (
args = {},
type = `response`,
response = { statusCode: 200 }
) => {
const url = `https://images.whatever.com/real-image-trust-me-${uuid}.png`

const gotMock = {
Expand All @@ -117,21 +121,14 @@ describe(`create-remote-file-node`, () => {
got.stream.mockReturnValueOnce({
pipe: jest.fn(() => gotMock),
on: jest.fn((mockType, mockCallback) => {
if (mockType === `response`) {
if (mockType === type) {
// got throws on 404/500 so we mimic this behaviour
if (response.statusCode === 404) {
throw new Error(`Response code 404 (Not Found)`)
}

mockCallback(response)
}
if (mockType === `downloadProgress`) {
mockCallback({
progress: 1,
transferred: 1,
total: 1,
})
}

return gotMock
}),
Expand Down
Binary file not shown.

This file was deleted.

14 changes: 3 additions & 11 deletions packages/gatsby-source-filesystem/src/create-remote-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,6 @@ const requestRemoteNode = (url, headers, tmpFilename, httpOpts, attempt = 1) =>
},
...httpOpts,
})

let haveAllBytesBeenWritten = false
responseStream.on(`downloadProgress`, progress => {
if (progress.transferred === progress.total || progress.total === null) {
haveAllBytesBeenWritten = true
}
})

const fsWriteStream = fs.createWriteStream(tmpFilename)
responseStream.pipe(fsWriteStream)

Expand All @@ -188,12 +180,12 @@ const requestRemoteNode = (url, headers, tmpFilename, httpOpts, attempt = 1) =>

responseStream.on(`response`, response => {
resetTimeout()
const contentLength =
response.headers && Number(response.headers[`content-length`])

fsWriteStream.on(`finish`, () => {
fsWriteStream.close()

// We have an incomplete download
if (!haveAllBytesBeenWritten) {
if (contentLength && contentLength !== fsWriteStream.bytesWritten) {
fs.removeSync(tmpFilename)

if (attempt < INCOMPLETE_RETRY_LIMIT) {
Expand Down
Loading

0 comments on commit 7e9ee09

Please sign in to comment.