Skip to content

Commit

Permalink
Merge pull request #166 from jaydenseric/fs-capacitor-4
Browse files Browse the repository at this point in the history
Upgrade to fs-capacitor v4.
  • Loading branch information
jaydenseric committed Nov 18, 2019
2 parents c3a789e + 9365f42 commit 7c8e4e5
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 269 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macos-latest]
node: ['8', '10', '12']
node: ['8', '10', '12', '13']
steps:
- uses: actions/checkout@v1
- name: Setup Node.js v${{ matrix.node }}
Expand Down
5 changes: 5 additions & 0 deletions changelog.md
Expand Up @@ -6,13 +6,18 @@

- Updated Node.js support from v8.5+ to v8.10+, to match what the [`eslint`](https://npm.im/eslint) dev dependency now supports. This is unlikely to be a breaking change for the published package.

### Minor

- Updated the [`fs-capacitor`](https://npm.im/fs-capacitor) dependency to v4 to support Node.js v13, making required changes to the source and tests, via [#166](https://github.com/jaydenseric/graphql-upload/pull/166).

### Patch

- Updated dev dependencies.
- Removed the `.nycrc.json` file:
- [`tap`](https://npm.im/tap) now ignores test files by default.
- The `lib/test-helpers` directory is now ignored using [`tap`](https://npm.im/tap) CLI arguments due to [tapjs/node-tap#612](https://github.com/tapjs/node-tap/issues/612).
- Updated the “Support” section of the readme to clarify varying native ESM support across Node.js versions.
- No longer test [`fs-capacitor`](https://npm.im/fs-capacitor) implementation details such as temp file creation and cleanup.

## 8.1.0

Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"busboy": "^0.3.1",
"fs-capacitor": "^2.0.4",
"fs-capacitor": "^4.0.0",
"http-errors": "^1.7.3",
"object-path": "^0.11.4"
},
Expand Down
24 changes: 13 additions & 11 deletions src/processRequest.mjs
@@ -1,12 +1,14 @@
import util from 'util'
import Busboy from 'busboy'
import { WriteStream } from 'fs-capacitor'
import fsCapacitor from 'fs-capacitor'
import createError from 'http-errors'
import objectPath from 'object-path'
import { SPEC_URL } from './constants'
import { ignoreStream } from './ignoreStream'
import { isEnumerableObject } from './isEnumerableObject'

const { WriteStream } = fsCapacitor

/**
* An expected file upload.
* @kind class
Expand Down Expand Up @@ -139,7 +141,7 @@ export const processRequest = (

if (map)
for (const upload of map.values())
if (upload.file) upload.file.capacitor.destroy()
if (upload.file) upload.file.capacitor.release()
}

/**
Expand Down Expand Up @@ -302,6 +304,7 @@ export const processRequest = (
return
}

let fileError
const capacitor = new WriteStream()

capacitor.on('error', () => {
Expand All @@ -310,29 +313,27 @@ export const processRequest = (
})

stream.on('limit', () => {
stream.unpipe()
capacitor.destroy(
createError(
413,
`File truncated as it exceeds the ${maxFileSize} byte size limit.`
)
fileError = createError(
413,
`File truncated as it exceeds the ${maxFileSize} byte size limit.`
)
stream.unpipe()
capacitor.destroy(fileError)
})

stream.on('error', error => {
fileError = error
stream.unpipe()
// istanbul ignore next
capacitor.destroy(exitError || error)
})

stream.pipe(capacitor)

const file = {
filename,
mimetype,
encoding,
createReadStream() {
const error = capacitor.error || (released ? exitError : null)
const error = fileError || (released ? exitError : null)
if (error) throw error
return capacitor.createReadStream()
}
Expand All @@ -348,6 +349,7 @@ export const processRequest = (

Object.defineProperty(file, 'capacitor', { value: capacitor })

stream.pipe(capacitor)
upload.resolve(file)
})

Expand Down

0 comments on commit 7c8e4e5

Please sign in to comment.