Skip to content

Commit

Permalink
Gzip compress Circulars archive
Browse files Browse the repository at this point in the history
  • Loading branch information
lpsinger committed Sep 8, 2023
1 parent caac7d2 commit d3fbfe1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/routes/circulars._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ function DownloadModal() {
<ModalToggleButton modalRef={modalRef} closer>
<a
className="text-no-underline text-white"
href="/circulars/archive.txt.tar"
href="/circulars/archive.txt.tar.gz"
>
Text
</a>
Expand All @@ -227,7 +227,7 @@ function DownloadModal() {
<ModalToggleButton modalRef={modalRef} closer>
<a
className="text-no-underline text-white"
href="/circulars/archive.json.tar"
href="/circulars/archive.json.tar.gz"
>
JSON
</a>
Expand Down
File renamed without changes.
9 changes: 6 additions & 3 deletions app/scheduled/circulars/uploadTar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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) {
Expand All @@ -39,13 +41,14 @@ function createUploadAction(
formatter: (circular: Circular) => string
): CircularAction<{ pack: Pack; promise: Promise<any> }> {
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 },
Expand Down

0 comments on commit d3fbfe1

Please sign in to comment.