Skip to content

Commit 7e9ee09

Browse files
committed
Revert "fix(gatsby-source-filesystem): fix broken stream with gzipped files (#28913)"
This reverts commit 38c0f42
1 parent 38c0f42 commit 7e9ee09

File tree

7 files changed

+18
-413
lines changed

7 files changed

+18
-413
lines changed

packages/gatsby-source-filesystem/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
"@babel/cli": "^7.12.1",
2626
"@babel/core": "^7.12.3",
2727
"babel-preset-gatsby-package": "^0.10.0",
28-
"cross-env": "^7.0.3",
29-
"msw": "^0.25.0"
28+
"cross-env": "^7.0.3"
3029
},
3130
"homepage": "https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-filesystem#readme",
3231
"keywords": [

packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node-integration.js

-268
This file was deleted.

packages/gatsby-source-filesystem/src/__tests__/create-remote-file-node.js

+6-9
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ describe(`create-remote-file-node`, () => {
100100
describe(`valid url`, () => {
101101
let uuid = 0
102102

103-
const setup = (args = {}, response = { statusCode: 200 }) => {
103+
const setup = (
104+
args = {},
105+
type = `response`,
106+
response = { statusCode: 200 }
107+
) => {
104108
const url = `https://images.whatever.com/real-image-trust-me-${uuid}.png`
105109

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

126130
mockCallback(response)
127131
}
128-
if (mockType === `downloadProgress`) {
129-
mockCallback({
130-
progress: 1,
131-
transferred: 1,
132-
total: 1,
133-
})
134-
}
135132

136133
return gotMock
137134
}),
Binary file not shown.

packages/gatsby-source-filesystem/src/__tests__/fixtures/gatsby-logo.svg

-5
This file was deleted.

packages/gatsby-source-filesystem/src/create-remote-file-node.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,6 @@ const requestRemoteNode = (url, headers, tmpFilename, httpOpts, attempt = 1) =>
159159
},
160160
...httpOpts,
161161
})
162-
163-
let haveAllBytesBeenWritten = false
164-
responseStream.on(`downloadProgress`, progress => {
165-
if (progress.transferred === progress.total || progress.total === null) {
166-
haveAllBytesBeenWritten = true
167-
}
168-
})
169-
170162
const fsWriteStream = fs.createWriteStream(tmpFilename)
171163
responseStream.pipe(fsWriteStream)
172164

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

189181
responseStream.on(`response`, response => {
190182
resetTimeout()
183+
const contentLength =
184+
response.headers && Number(response.headers[`content-length`])
191185

192186
fsWriteStream.on(`finish`, () => {
193-
fsWriteStream.close()
194-
195187
// We have an incomplete download
196-
if (!haveAllBytesBeenWritten) {
188+
if (contentLength && contentLength !== fsWriteStream.bytesWritten) {
197189
fs.removeSync(tmpFilename)
198190

199191
if (attempt < INCOMPLETE_RETRY_LIMIT) {

0 commit comments

Comments
 (0)