Parcourir la source

Disable auto-decompression in GCS persistor

The GCS library automatically decompresses files with Content-encoding:
gzip. This is very useful, but the S3 library doesn't do that, so we
need to disable the feature in GCS so that it behaves the same way other
persistors behave.
Eric Mc Sween il y a 6 ans
Parent
commit
967dde280e

+ 1 - 1
libraries/object-persistor/src/GcsPersistor.js

@@ -102,7 +102,7 @@ module.exports = class GcsPersistor extends AbstractPersistor {
     const stream = this.storage
     const stream = this.storage
       .bucket(bucketName)
       .bucket(bucketName)
       .file(key)
       .file(key)
-      .createReadStream(opts)
+      .createReadStream({ decompress: false, ...opts })
 
 
     // ingress to us from gcs
     // ingress to us from gcs
     const observer = new PersistorHelper.ObserverStream({
     const observer = new PersistorHelper.ObserverStream({

+ 7 - 0
libraries/object-persistor/test/unit/GcsPersistorTests.js

@@ -160,6 +160,12 @@ describe('GcsPersistorTests', function () {
         expect(GcsFile.createReadStream).to.have.been.called
         expect(GcsFile.createReadStream).to.have.been.called
       })
       })
 
 
+      it('disables automatic decompression', function () {
+        expect(GcsFile.createReadStream).to.have.been.calledWith({
+          decompress: false
+        })
+      })
+
       it('pipes the stream through the meter', function () {
       it('pipes the stream through the meter', function () {
         expect(ReadStream.pipe).to.have.been.calledWith(
         expect(ReadStream.pipe).to.have.been.calledWith(
           sinon.match.instanceOf(Transform)
           sinon.match.instanceOf(Transform)
@@ -183,6 +189,7 @@ describe('GcsPersistorTests', function () {
 
 
       it('passes the byte range on to GCS', function () {
       it('passes the byte range on to GCS', function () {
         expect(GcsFile.createReadStream).to.have.been.calledWith({
         expect(GcsFile.createReadStream).to.have.been.calledWith({
+          decompress: false,
           start: 5,
           start: 5,
           end: 10
           end: 10
         })
         })