Skip to content

Commit

Permalink
fix(gatsby-source-filesystem): Use new FileType methods to read file …
Browse files Browse the repository at this point in the history
…extension (gatsbyjs#28156)
  • Loading branch information
pvdz authored Nov 18, 2020
1 parent 37cf2ba commit 0267709
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
"@babel/runtime": "^7.12.5",
"better-queue": "^3.8.10",
"chokidar": "^3.4.3",
"file-type": "^12.4.2",
"file-type": "^16.0.0",
"fs-extra": "^8.1.0",
"gatsby-core-utils": "^1.6.0-next.0",
"got": "^9.6.0",
"md5-file": "^5.0.0",
"mime": "^2.4.6",
"pretty-bytes": "^5.4.1",
"progress": "^2.0.3",
"read-chunk": "^3.2.0",
"valid-url": "^1.0.9",
"xstate": "^4.14.0"
},
Expand Down
2 changes: 1 addition & 1 deletion src/create-file-node-from-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ async function processBufferNode({
// If the user did not provide an extension and we couldn't get
// one from remote file, try and guess one
if (typeof ext === `undefined`) {
const filetype = fileType(buffer)
const filetype = await fileType.fromBuffer(buffer)
ext = filetype ? `.${filetype.ext}` : `.bin`
}

Expand Down
4 changes: 1 addition & 3 deletions src/create-remote-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const { createContentDigest } = require(`gatsby-core-utils`)
const path = require(`path`)
const { isWebUri } = require(`valid-url`)
const Queue = require(`better-queue`)
const readChunk = require(`read-chunk`)
const fileType = require(`file-type`)
const { createProgress } = require(`./utils`)

Expand Down Expand Up @@ -290,8 +289,7 @@ async function fetchRemoteNode({
if (ext === ``) {
if (response.statusCode === 200) {
// if this is fresh response - try to guess extension and cache result for future
const buffer = readChunk.sync(tmpFilename, 0, fileType.minimumBytes)
const filetype = fileType(buffer)
const filetype = await fileType.fromFile(tmpFilename)
if (filetype) {
ext = `.${filetype.ext}`
await cache.set(cacheIdForExtensions(url), ext)
Expand Down

0 comments on commit 0267709

Please sign in to comment.