Skip to content

SdkZipService

reference
1 min readUpdated

Kind: Service

Source: atloria-monorepo/apps/sdk-worker/src/app/sdk-gen/sdk-zip.service.ts

Zips a generated package directory into a single in-memory buffer.

SdkZipService packages a generated SDK directory into a single in-memory Buffer. It is used by the SDK worker after generation completes, providing an archive payload that can be returned, uploaded, or persisted without writing an intermediate ZIP file.

Methods

MethodSignatureReturns
zipDirectoryzipDirectory(dir: string)Promise<Buffer>

Diagram

mermaid
sequenceDiagram
    participant Generator as SDK Generator
    participant ZipService as SdkZipService
    participant FS as Generated Package Directory
    participant Consumer as Upload/Response Consumer

    Generator->>ZipService: zipDirectory()
    ZipService->>FS: Read generated package files
    FS-->>ZipService: File contents and directory structure
    ZipService->>ZipService: Create ZIP archive in memory
    ZipService-->>Generator: Promise<Buffer>
    Generator->>Consumer: Upload or return ZIP buffer

Usage

ts
import { Injectable } from '@nestjs/common';
import { SdkZipService } from './sdk-zip.service';

@Injectable()
export class SdkExportService {
  constructor(private readonly sdkZipService: SdkZipService) {}

  async createDownloadPayload(): Promise<Buffer> {
    const zipBuffer = await this.sdkZipService.zipDirectory();

    // For example, pass the buffer to storage or an HTTP response.
    return zipBuffer;
  }
}

AI Coding Instructions

  • Keep ZIP creation in memory; zipDirectory() is expected to return a Promise<Buffer> rather than write a ZIP artifact to disk.
  • Invoke this service only after the SDK generation process has completed and the package directory contains all expected files.
  • Preserve the generated directory structure and ensure source paths are resolved safely before adding files to the archive.
  • Handle rejected promises at integration boundaries, especially when returning the archive through an HTTP endpoint or uploading it to object storage.
  • Avoid retaining returned buffers longer than necessary, as generated SDK archives may consume significant memory.

Referenced By

  • SdkGenModule (MODULE_PROVIDES)

Was this page helpful?

Download as PDF