Eazip

@eazip/core

Reference for Core functions, ZIP options, jobs, results, errors, and package entry points.

npm install @eazip/core

Primary functions

FunctionReturnsUse it when
createZip(options)Promise<ZipResult>You only need the finished output.
startZip(options)ZipJobYou need progress, cancellation, or observable state.

Both use Local execution unless strategy: 'cloud' is present.

createZip(options)

import { createZip } from '@eazip/core';

const result = await createZip({
  files,
  zipName: 'export.zip',
});

result.download();

The promise resolves for completed and partial output. It rejects for validation, cancellation, and fatal failures.

Shared options

OptionTypeDefaultDescription
filesZipInputrequired for source-created jobsFiles, blobs, URLs, or source objects.
zipNamestring'download.zip'Output name; .zip is added when omitted.
strategy'local' | 'cloud''local'Execution location.
failOnUrlErrorbooleanfalseFail instead of keeping usable output.
maxZipSizeBytesnumberBest-effort output part size.
signalAbortSignalCancels Local work or stops Cloud polling.
fetchFetchLikeglobal fetchCustom source and Cloud requests.
onChange(snapshot) => voidCalled after job snapshot changes.

Local options

OptionTypeDefaultDescription
compressionLevelinteger 096Deflate compression level.
concurrencynumber4Maximum parallel URL fetches.
onProgress(progress) => voidLocal file and byte progress.

Frontend-created Cloud options

OptionTypeDefaultDescription
strategy'cloud'requiredSelects Cloud execution.
publicKeystringrequiredBrowser-safe pk_ez_... key.
filesZipInputrequiredURL sources; File and Blob values fail validation.
apiBaseUrlstringSDK Cloud endpointOverrides the Cloud API origin.
mode'stream' | 'stored''stream'Cloud delivery mode.
turnstileTokenstringPre-obtained challenge token.
onChallenge(challenge) => Promise<string>Resolves a requested challenge once.
pollingPollingOptionsSDK defaultsOverrides Cloud polling behavior.

For backend-created Cloud jobs, pass createSession(context) instead of files and publicKey. filesTotal can provide an initial UI count.

Results

Both strategies expose:

MemberDescription
strategy'local' or 'cloud'.
status'completed' or 'partial'.
zipsOne entry per output ZIP.
errorsPer-file Local errors; currently empty for Cloud output.
skippedCountNumber of omitted sources.
download(index?)Downloads one ZIP, defaulting to index 0.
downloadAll()Downloads every output ZIP.

Local results also expose totalSize and dispose(). Cloud results expose sessionId, clientSecret, expiresAt, and session.

startZip(options)

import { startZip } from '@eazip/core';

const job = startZip({ files });
const unsubscribe = job.subscribe(() => {
  console.log(job.getSnapshot().status);
});

try {
  const result = await job.done;
  result.download();
} finally {
  unsubscribe();
}

startZip() accepts the same option shapes as createZip().

Job members

MemberDescription
idStable job identifier.
strategyFixed Local or Cloud strategy.
getSnapshot()Returns the current immutable snapshot.
subscribe(listener)Subscribes to changes and returns an unsubscribe function.
doneResolves with usable output or rejects with the terminal error.
abort()Stops Local work or Cloud polling.
download(index?)Downloads one ready output.
downloadAll()Downloads every ready output.
dispose()Releases Local object URLs; a no-op for Cloud.

Snapshot fields

FieldDescription
jobId / strategyJob identity and execution strategy.
statusstarting, processing, completed, partial, failed, or aborted.
progressLocal progress; null for Cloud.
zipsOutput available so far.
errors / skippedCountOmitted source information.
errorFatal error for a failed job.
sessionCloud session credentials and latest server job.
resultFinal result after completion or partial completion.

Resume Cloud jobs

import { resumeZip } from '@eazip/core';

const job = resumeZip({
  sessionId,
  clientSecret,
  apiBaseUrl,
});

resumeZip() returns a ZipJob. It reconnects to an existing session and does not create a new job.

Errors

All SDK errors extend EazipErrorBase. Use isEazipError() to narrow an unknown value and read its stable code.

ClassTypical condition
EazipValidationErrorInvalid input, missing key, or API misuse.
EazipAbortErrorThe job or supplied signal was aborted.
EazipNetworkErrorA browser or Cloud request could not be made.
EazipApiErrorCloud API error without a more specific subclass.
EazipChallengeRequiredErrorCloud requires an anti-abuse challenge.
EazipRateLimitErrorCloud rate limit; may include retryAfterMs.
EazipQuotaErrorCloud plan or quota limit.
EazipJobFailedErrorThe server-side ZIP job failed.
EazipSessionExpiredError / EazipSessionRevokedErrorSession credentials are no longer usable.
EazipDownloadExpiredErrorA Cloud output link is no longer usable.

Package entry points

ImportNotable exports
@eazip/coreRecommended functions, shared types, and errors.
@eazip/core/localcreateLocalZip, startLocalZip, and filename utilities.
@eazip/core/cloudstartCloudZip, resumeZip, SessionsClient, and DEFAULT_API_BASE_URL.
@eazip/core/sharedShared types, errors, input normalization, download, and abort helpers.

Use specialized entry points only when bundle boundaries or lower-level Cloud session access require them.