From d3fbfe1376381bd3f3f41d08341145cdabc0696f Mon Sep 17 00:00:00 2001 From: Leo Singer Date: Fri, 8 Sep 2023 12:13:23 -0400 Subject: [PATCH] Gzip compress Circulars archive --- app/routes/circulars._index.tsx | 4 ++-- ...n[.]tar.ts => circulars.archive[.]json[.]tar[.]gz.ts} | 0 ...xt[.]tar.ts => circulars.archive[.]txt[.]tar[.]gz.ts} | 0 app/scheduled/circulars/uploadTar.ts | 9 ++++++--- 4 files changed, 8 insertions(+), 5 deletions(-) rename app/routes/{circulars.archive[.]json[.]tar.ts => circulars.archive[.]json[.]tar[.]gz.ts} (100%) rename app/routes/{circulars.archive[.]txt[.]tar.ts => circulars.archive[.]txt[.]tar[.]gz.ts} (100%) diff --git a/app/routes/circulars._index.tsx b/app/routes/circulars._index.tsx index a33059dea..da7892a27 100644 --- a/app/routes/circulars._index.tsx +++ b/app/routes/circulars._index.tsx @@ -218,7 +218,7 @@ function DownloadModal() { Text @@ -227,7 +227,7 @@ function DownloadModal() { JSON diff --git a/app/routes/circulars.archive[.]json[.]tar.ts b/app/routes/circulars.archive[.]json[.]tar[.]gz.ts similarity index 100% rename from app/routes/circulars.archive[.]json[.]tar.ts rename to app/routes/circulars.archive[.]json[.]tar[.]gz.ts diff --git a/app/routes/circulars.archive[.]txt[.]tar.ts b/app/routes/circulars.archive[.]txt[.]tar[.]gz.ts similarity index 100% rename from app/routes/circulars.archive[.]txt[.]tar.ts rename to app/routes/circulars.archive[.]txt[.]tar[.]gz.ts diff --git a/app/scheduled/circulars/uploadTar.ts b/app/scheduled/circulars/uploadTar.ts index 1d070c14d..a9c46b95e 100644 --- a/app/scheduled/circulars/uploadTar.ts +++ b/app/scheduled/circulars/uploadTar.ts @@ -9,6 +9,7 @@ import { S3Client } from '@aws-sdk/client-s3' import { Upload } from '@aws-sdk/lib-storage' import { basename } from 'node:path' import { PassThrough } from 'node:stream' +import { createGzip } from 'node:zlib' import type { Pack } from 'tar-stream' import { pack as tarPack } from 'tar-stream' @@ -21,9 +22,10 @@ import { } from '~/routes/circulars/circulars.lib' const s3 = new S3Client({}) +const archiveSuffix = '.tar.gz' function getBucketKey(suffix: string) { - return `circulars/archive.${suffix}.tar` + return `circulars/archive.${suffix}${archiveSuffix}` } function getBucketUrl(region: string, bucket: string, key: string) { @@ -39,13 +41,14 @@ function createUploadAction( formatter: (circular: Circular) => string ): CircularAction<{ pack: Pack; promise: Promise }> { const Key = getBucketKey(suffix) - const tarDir = basename(Key, '.tar') + const tarDir = basename(Key, archiveSuffix) return { initialize() { const pack = tarPack() + const gzip = createGzip() const Body = new PassThrough() - pack.pipe(Body) + pack.pipe(gzip).pipe(Body) const promise = new Upload({ client: s3, params: { Body, Bucket, Key },