@mlightcad/common
Version:
[](https://opensource.org/licenses/MIT) [](https://www.npmjs.com/package/@mlightcad/common)
95 lines • 3.71 kB
TypeScript
/**
* @fileoverview HTTP-based file loader implementation for the AutoCAD Common library.
*
* This module provides a concrete implementation of the loader interface using
* the Fetch API for loading files over HTTP. Supports various response types
* and provides comprehensive error handling.
*
* @module AcCmFileLoader
* @version 1.0.0
*/
import { AcCmLoader, AcCmLoaderProgressCallback } from './AcCmLoader';
import { AcCmLoadingManager, AcCmOnErrorCallback, AcCmOnLoadCallback } from './AcCmLoadingManager';
/**
* The supported response types for file loading operations.
*
* - `''` or `'text'` - Returns the data as a string (default).
* - `'arraybuffer'` - Loads the data into an ArrayBuffer.
* - `'blob'` - Returns the data as a Blob.
* - `'document'` - Parses the file using the DOMParser.
* - `'json'` - Parses the file using JSON.parse.
*/
type AcCmResponseType = '' | 'text' | 'arraybuffer' | 'blob' | 'document' | 'json';
/**
* HTTP-based file loader using the Fetch API.
*
* A low-level class for loading resources over HTTP, used internally by most loaders.
* It can also be used directly to load any file type that does not have a specialized loader.
*
* Supports various response types, custom MIME types, and provides comprehensive error handling
* with automatic retry mechanisms for failed requests.
*
* @example
* ```typescript
* import { AcCmFileLoader } from './AcCmFileLoader'
*
* const loader = new AcCmFileLoader()
*
* // Load a text file
* loader.load(
* 'data.txt',
* (data) => console.log('Loaded:', data),
* (progress) => console.log('Progress:', progress.loaded / progress.total),
* (error) => console.error('Error:', error)
* )
*
* // Load binary data
* loader.setResponseType('arraybuffer')
* loader.load('file.dwg', (arrayBuffer) => {
* // Process binary data
* })
* ```
*/
export declare class AcCmFileLoader extends AcCmLoader {
/**
* The expected mimeType. Default is undefined.
*/
mimeType?: DOMParserSupportedType;
/**
* The expected response type. Default is undefined.
*/
responseType?: AcCmResponseType;
/**
* Create a new AcCmFileLoader instance.
* @param manager The loadingManager for the loader to use. Default is DefaultLoadingManager.
*/
constructor(manager?: AcCmLoadingManager);
/**
* Load the URL and pass the response to the onLoad function.
* @param url The path or URL to the file. This can also be a Data URI.
* @param onLoad (optional) — Will be called when loading completes.
* @param onProgress (optional) — Will be called while load progresses.
* @param onError (optional) — Will be called if an error occurs.
*/
load(url: string, onLoad: AcCmOnLoadCallback, onProgress: AcCmLoaderProgressCallback, onError: AcCmOnErrorCallback): void;
/**
* Change the response type. Valid values are:
* - text or empty string (default) - returns the data as String.
* - arraybuffer - loads the data into a ArrayBuffer and returns that.
* - blob - returns the data as a Blob.
* - document - parses the file using the DOMParser.
* - json - parses the file using JSON.parse.
* @param value
* @returns Return this object
*/
setResponseType(value: AcCmResponseType): this;
/**
* Set the expected mimeType of the file being loaded. Note that in many cases this will be determined
* automatically, so by default it is undefined.
* @param value The expected mimeType of the file being loaded.
* @returns Return this object.
*/
setMimeType(value: DOMParserSupportedType): this;
}
export {};
//# sourceMappingURL=AcCmFileLoader.d.ts.map