Skip to content

Commit

Permalink
perf: tweak up zip layer
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 8, 2022
1 parent 0306fe7 commit 324759b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/main/js/zip.js
Expand Up @@ -3,9 +3,13 @@ import os from 'node:os'
import {promisify} from 'node:util'
import {Buffer} from 'node:buffer'

import { getConfig } from './config.js'
import { runWorker } from './worker/index.js'

const cpulen = os.cpus().length
export const gzip = async (data) => (getConfig()?.workerConcurrency || os.cpus().length) === 1
? promisify(zlib.gzip)(data)
: runWorker('worker-zip.js', { method: 'gzip', args: [data] }).then(Buffer.from)

export const gzip = cpulen === 1 ? promisify(zlib.gzip) : async (data) => runWorker('worker-zip.js', { method: 'gzip', args: [data] }).then(Buffer.from)
export const gunzip = cpulen === 1 ? promisify(zlib.gunzip) : async (data) => runWorker('worker-zip.js', { method: 'gunzip', args: [data] }).then(Buffer.from)
export const gunzip = async (data) => (getConfig()?.workerConcurrency || os.cpus().length) === 1
? promisify(zlib.gunzip)(data)
: runWorker('worker-zip.js', { method: 'gunzip', args: [data] }).then(Buffer.from)

0 comments on commit 324759b

Please sign in to comment.