• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dex4er / js-fs-gzip-blob-storage / #572

23 Jun 2024 11:19PM UTC coverage: 100.0%. Remained the same
#572

push

dex4er
Bump date

11 of 11 branches covered (100.0%)

Branch coverage included in aggregate %.

93 of 93 relevant lines covered (100.0%)

5.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/src/fs-gzip-blob-storage.ts
1
/// <reference types="node" />
1✔
2

1✔
3
import {Readable, Writable} from "node:stream"
1✔
4
import zlib from "node:zlib"
1✔
5

1✔
6
import Pumpify from "pumpify"
1✔
7

1✔
8
import {
1✔
9
  FsBlobStorage,
1✔
10
  FsBlobStorageCommitOptions,
1✔
11
  FsBlobStorageOptions,
1✔
12
  FsBlobStorageReadStreamOptions,
1✔
13
  FsBlobStorageRemoveOptions,
1✔
14
  FsBlobStorageWriteStreamOptions,
1✔
15
  DEFAULT_EXT,
1✔
16
} from "fs-blob-storage"
1✔
17

1✔
18
export interface FsGzipBlobStorageOptions extends FsBlobStorageOptions {
1✔
19
  gzipExt?: string
1✔
20
  gzipOptions?: zlib.ZlibOptions
1✔
21
}
1✔
22

1✔
23
export interface FsGzipBlobStorageReadStreamOptions extends FsBlobStorageReadStreamOptions {
1✔
24
  encoding?: never
1✔
25
}
1✔
26

1✔
27
export interface FsGzipBlobStorageWriteStreamOptions extends FsBlobStorageWriteStreamOptions {
1✔
28
  encoding?: never
1✔
29
}
1✔
30

1✔
31
export interface FsGzipBlobStorageCommitOptions extends FsBlobStorageCommitOptions {}
1✔
32
export interface FsGzipBlobStorageRemoveOptions extends FsBlobStorageRemoveOptions {}
1✔
33

1✔
34
export {DEFAULT_EXT, DEFAULT_PART} from "fs-blob-storage"
1✔
35

1✔
36
export const DEFAULT_GZIP_EXT = ".gz"
1✔
37

1✔
38
export class FsGzipBlobStorage {
1✔
39
  private storage: FsBlobStorage
1✔
40
  private ext: string
1✔
41
  private gzipExt: string
1✔
42
  private gzipOptions: zlib.ZlibOptions
1✔
43

1✔
44
  constructor(options: FsGzipBlobStorageOptions = {}) {
1✔
45
    this.storage = new FsBlobStorage(options)
34✔
46
    this.ext = options.ext !== undefined ? options.ext : DEFAULT_EXT
34✔
47
    this.gzipExt = options.gzipExt !== undefined ? options.gzipExt : DEFAULT_GZIP_EXT
34✔
48
    this.gzipOptions = options.gzipOptions || {}
34✔
49
  }
34✔
50

1✔
51
  async createWriteStream(key: string, options: FsGzipBlobStorageWriteStreamOptions = {}): Promise<Writable> {
1✔
52
    const {ext = this.ext} = options
10✔
53
    const gz = this.gzipExt
10✔
54

10✔
55
    const newOptions = Object.assign({}, options, {ext: ext + gz, encoding: null})
10✔
56

10✔
57
    const file = await this.storage.createWriteStream(key, newOptions)
10✔
58
    const gzip = zlib.createGzip(this.gzipOptions)
8✔
59
    return new Pumpify(gzip, file)
8✔
60
  }
8✔
61

1✔
62
  async createReadStream(key: string, options: FsGzipBlobStorageReadStreamOptions = {}): Promise<Readable> {
1✔
63
    const {ext = this.ext} = options
8✔
64
    const gz = this.gzipExt
8✔
65

8✔
66
    const newOptions = Object.assign({}, options, {ext: ext + gz, encoding: null})
8✔
67

8✔
68
    const file = await this.storage.createReadStream(key, newOptions)
8✔
69
    const gunzip = zlib.createGunzip(this.gzipOptions)
6✔
70

6✔
71
    return new Pumpify(file, gunzip)
6✔
72
  }
6✔
73

1✔
74
  commit(key: string, options: FsGzipBlobStorageCommitOptions = {}): Promise<void> {
1✔
75
    const {ext = this.ext} = options
8✔
76
    const gz = this.gzipExt
8✔
77

8✔
78
    const newOptions = Object.assign({}, options, {ext: ext + gz})
8✔
79

8✔
80
    return this.storage.commit(key, newOptions)
8✔
81
  }
8✔
82

1✔
83
  remove(key: string, options: FsGzipBlobStorageRemoveOptions = {}): Promise<void> {
1✔
84
    const {ext = this.ext} = options
7✔
85
    const gz = this.gzipExt
7✔
86

7✔
87
    const newOptions = Object.assign({}, options, {ext: ext + gz})
7✔
88

7✔
89
    return this.storage.remove(key, newOptions)
7✔
90
  }
7✔
91
}
1✔
92

1✔
93
export default FsGzipBlobStorage
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc