UNPKG

@esri/solution-common

Version:

Provides general helper functions for @esri/solution.js.

86 lines (85 loc) 3.69 kB
/** @license * Copyright 2024 Esri * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import JSZip from "jszip"; import { TZipObjectContent, IZipObjectContentItem } from "./interfaces"; import { UserSession } from "./arcgisRestJS"; /** * Converts a blob to a zip file. * * @param blob Blob to convert * @returns Promise resolving to zip object */ export declare function blobToZipObject(blob: Blob): Promise<JSZip>; /** * Fetches a zip object. * * @param formZipFilePath Path to the zip file * @param authentication Credentials to zip file * @returns Promise resolving to zip object */ export declare function fetchZipObject(formZipFilePath: string, authentication: UserSession): Promise<JSZip>; /** * Gets the contents of the files in the zip. * * @param zip Zip file * @param filesOfInterest Array of file names to extract from the zip file. If empty, all files are extracted. * @param blobExtensions Array of file extensions to treat as blobs; defaults to * ["png", "jpeg", "jpg", "gif", "svg", "xls", "xlsx"] * @returns Promise that resolves to an array of objects containing the file name and contents */ export declare function getZipObjectContents(zipObject: JSZip, filesOfInterest?: string[], blobExtensions?: string[]): Promise<IZipObjectContentItem[]>; /** * Converts a JSON object of keys (filenames)/content (stringified JSON) to a zip object. * * @param zippedFileJson JSON object to convert * @returns Created zip object */ export declare function jsonFilesToZipObject(zippedFileJson: any): JSZip; /** * Converts a JSON object to a zip object. * * @param zippedFileName Name of the file in the zip * @param zippedFileJson JSON object to convert * @returns Created zip object */ export declare function jsonToZipObject(zippedFileName: string, zippedFileJson: any): JSZip; /** * Converts a JSON object to a zip file. * * @param zippedFileName Name of the file in the zip file * @param zippedFileJson JSON object to convert * @param filename Name to use for zip file; ".zip" added if missing * @returns Promise resolving to zip file */ export declare function jsonToZipFile(zippedFileName: string, zippedFileJson: any, filename: string): Promise<File>; /** * Extracts files of interest from a zip object, calls a supplied function to modify them, and * restores the files into the zip object. * * @param modificationCallback Function that modifies the specified files * @param zip Zip file that contains the files to modify; modified in place * @param filesOfInterest Array of file names to extract from the zip file. If empty, all files are extracted. * @returns Promise that resolves to the modified zip file if the swizzle was successful */ export declare function modifyFilesinZipObject(modificationCallback: (zipContentStr: IZipObjectContentItem) => TZipObjectContent, zipObject: JSZip, filesOfInterest?: string[]): Promise<JSZip>; /** * Converts a zip object to a zip file. * * @param zipObject Zip object * @param filename Name to use for zip file; ".zip" added if missing * @returns Promise resolving to zip file */ export declare function zipObjectToZipFile(zipObject: JSZip, filename: string): Promise<File>;