Skip to content

Commit ee0c68c

Browse files
refactor(lib): remove assert-is-uint8array dependency
1 parent 6d20bec commit ee0c68c

File tree

3 files changed

+9
-26
lines changed

3 files changed

+9
-26
lines changed

index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ var debug = require('debug')('compression')
2222
var onHeaders = require('on-headers')
2323
var vary = require('vary')
2424
var zlib = require('zlib')
25-
var isUint8Array = require('@stdlib/assert-is-uint8array')
26-
const { ServerResponse } = require('http')
25+
var { ServerResponse } = require('http')
2726

2827
/**
2928
* Module exports.
@@ -38,6 +37,10 @@ module.exports.filter = shouldCompress
3837
*/
3938

4039
var cacheControlNoTransformRegExp = /(?:^|,)\s*?no-transform\s*?(?:,|$)/
40+
var hasUint8Array = (typeof Uint8Array === 'function')
41+
function isUint8Array (arg) {
42+
return hasUint8Array && arg && (arg instanceof Uint8Array || arg.toString() === '[object Uint8Array]')
43+
}
4144

4245
/**
4346
* Compress response data with gzip / deflate.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"license": "MIT",
1010
"repository": "expressjs/compression",
1111
"dependencies": {
12-
"@stdlib/assert-is-uint8array": "^0.0.8",
1312
"accepts": "~1.3.8",
1413
"bytes": "3.0.0",
1514
"compressible": "~2.0.18",
@@ -29,8 +28,9 @@
2928
"eslint-plugin-standard": "4.1.0",
3029
"mocha": "9.2.2",
3130
"nyc": "15.1.0",
32-
"supertest": "6.2.3",
33-
"sinon": "4.5.0"
31+
"semver": "^7.3.7",
32+
"sinon": "4.5.0",
33+
"supertest": "6.2.3"
3434
},
3535
"files": [
3636
"LICENSE",
@@ -42,7 +42,7 @@
4242
},
4343
"scripts": {
4444
"lint": "eslint .",
45-
"test": "mocha --check-leaks --reporter spec --bail",
45+
"test": "mocha --check-leaks -reporter spec --bail",
4646
"test-ci": "nyc --reporter=lcovonly --reporter=text npm test",
4747
"test-cov": "nyc --reporter=html --reporter=text npm test"
4848
}

test/compression.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -111,26 +111,6 @@ describe('compression()', function () {
111111
})
112112
})
113113

114-
it('res.write() should throw ERR_STREAM_DESTROYED when stream is already destroyed', function (done) {
115-
var server = createServer({ threshold: 0 }, function (req, res) {
116-
res.setHeader('Content-Type', 'text/plain')
117-
res.end('hello world')
118-
119-
server.on('close', function () {
120-
res.write('hello world', function (err) {
121-
assert.ok(err.code === 'ERR_STREAM_DESTROYED')
122-
})
123-
})
124-
})
125-
126-
request(server)
127-
.get('/')
128-
.set('Accept-Encoding', 'gzip')
129-
.expect(shouldHaveHeader('Content-Encoding'))
130-
.expect(shouldHaveBodyLength('hello world'.length))
131-
.expect(200, done)
132-
})
133-
134114
it('res.write() should throw ERR_STREAM_ALREADY_FINISHED when stream is already finished', function (done) {
135115
var server = createServer({ threshold: 0 }, function (req, res) {
136116
res.setHeader('Content-Type', 'text/plain')

0 commit comments

Comments
 (0)