pr_15445.patch 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. --- services/history-v1/storage/lib/history_store.js
  2. +++ services/history-v1/storage/lib/history_store.js
  3. @@ -103,11 +103,11 @@ HistoryStore.prototype.storeRaw = function historyStoreStoreRaw(
  4. assert.object(rawHistory, 'bad rawHistory')
  5. const key = getKey(projectId, chunkId)
  6. - const stream = streams.gzipStringToStream(JSON.stringify(rawHistory))
  7. logger.debug({ projectId, chunkId }, 'storeRaw started')
  8. return BPromise.resolve()
  9. - .then(() =>
  10. + .then(() => streams.gzipStringToStream(JSON.stringify(rawHistory)))
  11. + .then(stream =>
  12. persistor.sendStream(BUCKET, key, stream, {
  13. contentType: 'application/json',
  14. contentEncoding: 'gzip',
  15. --- services/history-v1/storage/lib/streams.js
  16. +++ services/history-v1/storage/lib/streams.js
  17. @@ -79,8 +79,15 @@ function gunzipStreamToBuffer(readStream) {
  18. exports.gunzipStreamToBuffer = gunzipStreamToBuffer
  19. function gzipStringToStream(string) {
  20. - const gzip = zlib.createGzip()
  21. - return new ReadableString(string).pipe(gzip)
  22. + return new BPromise(function (resolve, reject) {
  23. + zlib.gzip(Buffer.from(string), function (error, result) {
  24. + if (error) {
  25. + reject(error)
  26. + } else {
  27. + resolve(new ReadableString(result))
  28. + }
  29. + })
  30. + })
  31. }
  32. /**
  33. @@ -88,6 +95,6 @@ function gzipStringToStream(string) {
  34. *
  35. * @function
  36. * @param {string} string
  37. - * @return {stream.Writable}
  38. + * @return {Promise.<stream.Readable>}
  39. */
  40. exports.gzipStringToStream = gzipStringToStream