From d9db37097245ce8ea3204c2f4f4d4ed32b5f3c10 Mon Sep 17 00:00:00 2001 From: Daria Terekhova <98411986+dariaterekhova-actionengine@users.noreply.github.com> Date: Wed, 15 May 2024 15:38:40 +0300 Subject: [PATCH] chore(loader-utils): Preparing to migrate from FileProviders to ReadableFiles (#3000) --- .../slpk-in-browser/src/browser-file.ts | 4 +- .../3d-tiles-archive-archive.ts | 8 +- .../3d-tiles-archive-parser.ts | 4 +- .../src/lib/parsers/parse-slpk/parse-slpk.ts | 4 +- .../lib/parsers/parse-slpk/slpk-archieve.ts | 8 +- modules/loader-utils/src/index.ts | 5 +- .../src/lib/file-provider/data-view-file.ts | 4 +- .../src/lib/file-provider/file-handle-file.ts | 4 +- .../file-provider/file-provider-interface.ts | 56 ++++++++ .../src/lib/file-provider/file-provider.ts | 120 ++++++++++++++---- modules/loader-utils/test/index.ts | 1 + .../lib/file-provider/file-provider.spec.ts | 40 ++++++ .../i3s-converter/helpers/load-3d-tiles.ts | 4 +- modules/zip/src/filesystems/IndexedArchive.ts | 10 +- modules/zip/src/filesystems/zip-filesystem.ts | 6 +- modules/zip/src/hash-file-utility.ts | 4 +- modules/zip/src/parse-zip/cd-file-header.ts | 6 +- .../src/parse-zip/end-of-central-directory.ts | 8 +- .../zip/src/parse-zip/local-file-header.ts | 8 +- .../zip/src/parse-zip/search-from-the-end.ts | 4 +- 20 files changed, 248 insertions(+), 60 deletions(-) create mode 100644 modules/loader-utils/src/lib/file-provider/file-provider-interface.ts create mode 100644 modules/loader-utils/test/lib/file-provider/file-provider.spec.ts diff --git a/examples/experimental/slpk-in-browser/src/browser-file.ts b/examples/experimental/slpk-in-browser/src/browser-file.ts index 0a7cb16b29..de36ec1f84 100644 --- a/examples/experimental/slpk-in-browser/src/browser-file.ts +++ b/examples/experimental/slpk-in-browser/src/browser-file.ts @@ -1,13 +1,13 @@ // loaders.gl // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; /** * Provides file data using node fs library * @deprecated - will be replaced with ReadableFile */ -export class BrowserFile implements FileProvider { +export class BrowserFile implements FileProviderInterface { /** The File object from which data is provided */ private file: File; diff --git a/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-archive.ts b/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-archive.ts index 55093b84f2..59b83be56c 100644 --- a/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-archive.ts +++ b/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-archive.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright vis.gl contributors -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; import {MD5Hash} from '@loaders.gl/crypto'; import {DeflateCompression, NoCompression} from '@loaders.gl/compression'; import {IndexedArchive, parseZipLocalFileHeader} from '@loaders.gl/zip'; @@ -31,7 +31,11 @@ export class Tiles3DArchive extends IndexedArchive { * @param fileProvider - FileProvider with the whole file * @param hashTable - hash info */ - constructor(fileProvider: FileProvider, hashTable?: Record, fileName?: string) { + constructor( + fileProvider: FileProviderInterface, + hashTable?: Record, + fileName?: string + ) { super(fileProvider, hashTable, fileName); this.hashTable = hashTable; } diff --git a/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-parser.ts b/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-parser.ts index 9344d3bb86..08d3c2aa7e 100644 --- a/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-parser.ts +++ b/modules/3d-tiles/src/3d-tiles-archive/3d-tiles-archive-parser.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright vis.gl contributors -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; import { CD_HEADER_SIGNATURE, makeHashTableFromZipHeaders, @@ -20,7 +20,7 @@ import {Tiles3DArchive} from './3d-tiles-archive-archive'; * @returns 3tz file handler */ export const parse3DTilesArchive = async ( - fileProvider: FileProvider, + fileProvider: FileProviderInterface, cb?: (msg: string) => void ): Promise => { const hashCDOffset = await searchFromTheEnd(fileProvider, CD_HEADER_SIGNATURE); diff --git a/modules/i3s/src/lib/parsers/parse-slpk/parse-slpk.ts b/modules/i3s/src/lib/parsers/parse-slpk/parse-slpk.ts index 1ff00bcc17..fcf2988c28 100644 --- a/modules/i3s/src/lib/parsers/parse-slpk/parse-slpk.ts +++ b/modules/i3s/src/lib/parsers/parse-slpk/parse-slpk.ts @@ -1,4 +1,4 @@ -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; import { parseZipCDFileHeader, CD_HEADER_SIGNATURE, @@ -16,7 +16,7 @@ import {SLPKArchive} from './slpk-archieve'; * @returns slpk file handler */ export async function parseSLPKArchive( - fileProvider: FileProvider, + fileProvider: FileProviderInterface, cb?: (msg: string) => void, fileName?: string ): Promise { diff --git a/modules/i3s/src/lib/parsers/parse-slpk/slpk-archieve.ts b/modules/i3s/src/lib/parsers/parse-slpk/slpk-archieve.ts index a24441cdba..e44e88b05a 100644 --- a/modules/i3s/src/lib/parsers/parse-slpk/slpk-archieve.ts +++ b/modules/i3s/src/lib/parsers/parse-slpk/slpk-archieve.ts @@ -1,5 +1,5 @@ import {MD5Hash} from '@loaders.gl/crypto'; -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; import {IndexedArchive, parseZipLocalFileHeader} from '@loaders.gl/zip'; import {GZipCompression} from '@loaders.gl/compression'; @@ -56,7 +56,11 @@ export class SLPKArchive extends IndexedArchive { * @param hashTable - pre-loaded hashTable. If presented, getFile will skip reading the hash file * @param fileName - name of the archive. It is used to add to an URL of a loader context */ - constructor(fileProvider: FileProvider, hashTable?: Record, fileName?: string) { + constructor( + fileProvider: FileProviderInterface, + hashTable?: Record, + fileName?: string + ) { super(fileProvider, hashTable, fileName); this.hashTable = hashTable; } diff --git a/modules/loader-utils/src/index.ts b/modules/loader-utils/src/index.ts index b6625e333f..e90387f3c9 100644 --- a/modules/loader-utils/src/index.ts +++ b/modules/loader-utils/src/index.ts @@ -133,8 +133,9 @@ export type {FileSystem, RandomAccessFileSystem} from './lib/filesystems/filesys export {NodeFileSystemFacade as NodeFilesystem} from './lib/filesystems/node-filesystem-facade'; // TODO - replace with ReadableFile -export type {FileProvider} from './lib/file-provider/file-provider'; -export {isFileProvider} from './lib/file-provider/file-provider'; +export type {FileProviderInterface} from './lib/file-provider/file-provider-interface'; +export {isFileProvider} from './lib/file-provider/file-provider-interface'; +export {FileProvider} from './lib/file-provider/file-provider'; export {FileHandleFile} from './lib/file-provider/file-handle-file'; export {DataViewFile} from './lib/file-provider/data-view-file'; diff --git a/modules/loader-utils/src/lib/file-provider/data-view-file.ts b/modules/loader-utils/src/lib/file-provider/data-view-file.ts index 5f38a6cd5c..49a380863c 100644 --- a/modules/loader-utils/src/lib/file-provider/data-view-file.ts +++ b/modules/loader-utils/src/lib/file-provider/data-view-file.ts @@ -1,4 +1,4 @@ -import {FileProvider} from './file-provider'; +import {FileProviderInterface} from './file-provider-interface'; /** * Checks if bigint can be converted to number and convert it if possible @@ -16,7 +16,7 @@ const toNumber = (bigint: bigint) => { * Provides file data using DataView * @deprecated - will be replaced with ReadableFile */ -export class DataViewFile implements FileProvider { +export class DataViewFile implements FileProviderInterface { /** The DataView from which data is provided */ private file: DataView; diff --git a/modules/loader-utils/src/lib/file-provider/file-handle-file.ts b/modules/loader-utils/src/lib/file-provider/file-handle-file.ts index 4835b055ff..4656fc3e85 100644 --- a/modules/loader-utils/src/lib/file-provider/file-handle-file.ts +++ b/modules/loader-utils/src/lib/file-provider/file-handle-file.ts @@ -2,14 +2,14 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {FileProvider} from './file-provider'; +import {FileProviderInterface} from './file-provider-interface'; import {NodeFileFacade as NodeFile} from '../files/node-file-facade'; /** * Provides file data using node fs library * @deprecated - will be replaced with ReadableFile */ -export class FileHandleFile implements FileProvider { +export class FileHandleFile implements FileProviderInterface { /** The FileHandle from which data is provided */ private file: NodeFile; diff --git a/modules/loader-utils/src/lib/file-provider/file-provider-interface.ts b/modules/loader-utils/src/lib/file-provider/file-provider-interface.ts new file mode 100644 index 0000000000..4611c9fb7f --- /dev/null +++ b/modules/loader-utils/src/lib/file-provider/file-provider-interface.ts @@ -0,0 +1,56 @@ +/** + * Interface for providing file data + */ +export interface FileProviderInterface { + /** + * Cleanup class data + */ + destroy(): Promise; + /** + * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file. + * @param offset The offset, in bytes, from the start of the file where to read the data. + */ + getUint8(offset: bigint): Promise; + + /** + * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file. + * @param offset The offset, in bytes, from the start of the file where to read the data. + */ + getUint16(offset: bigint): Promise; + + /** + * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file. + * @param offset The offset, in bytes, from the file of the view where to read the data. + */ + getUint32(offset: bigint): Promise; + + /** + * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file. + * @param offset The offset, in byte, from the file of the view where to read the data. + */ + getBigUint64(offset: bigint): Promise; + + /** + * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive. + * @param startOffset The offset, in bytes, from the start of the file where to start reading the data. + * @param endOffset The offset, in bytes, from the start of the file where to end reading the data. + */ + slice(startOffset: bigint, endOffset: bigint): Promise; + + /** + * the length (in bytes) of the data. + */ + length: bigint; +} + +/** + * Check is the object has FileProvider members + * @param fileProvider - tested object + */ +export const isFileProvider = (fileProvider: unknown) => { + return ( + (fileProvider as FileProviderInterface)?.getUint8 && + (fileProvider as FileProviderInterface)?.slice && + (fileProvider as FileProviderInterface)?.length + ); +}; diff --git a/modules/loader-utils/src/lib/file-provider/file-provider.ts b/modules/loader-utils/src/lib/file-provider/file-provider.ts index f7ed7f34c0..18f6136639 100644 --- a/modules/loader-utils/src/lib/file-provider/file-provider.ts +++ b/modules/loader-utils/src/lib/file-provider/file-provider.ts @@ -1,57 +1,127 @@ +// loaders.gl +// SPDX-License-Identifier: MIT +// Copyright (c) vis.gl contributors +import {ReadableFile} from '../files/file'; +import {FileProviderInterface} from './file-provider-interface'; + /** - * Interface for providing file data + * Provides file data using range requests to the server * @deprecated - will be replaced with ReadableFile */ -export interface FileProvider { +export class FileProvider implements FileProviderInterface { + /** The File object from which data is provided */ + private file: ReadableFile; + private size: bigint; + + /** Create a new BrowserFile */ + private constructor(file: ReadableFile, size: bigint | number) { + this.file = file; + this.size = BigInt(size); + } + + static async create(file: ReadableFile): Promise { + return new FileProvider( + file, + file.bigsize > 0n + ? file.bigsize + : file.size > 0n + ? file.size + : (await file.stat?.())?.bigsize ?? 0n + ); + } + /** - * Cleanup class data + * Truncates the file descriptor. + * @param length desired file lenght */ - destroy(): Promise; + async truncate(length: number): Promise { + throw new Error('file loaded via range requests cannot be changed'); + } + + /** + * Append data to a file. + * @param buffer data to append + */ + async append(buffer: Uint8Array): Promise { + throw new Error('file loaded via range requests cannot be changed'); + } + + /** Close file */ + async destroy(): Promise { + throw new Error('file loaded via range requests cannot be changed'); + } + /** * Gets an unsigned 8-bit integer at the specified byte offset from the start of the file. * @param offset The offset, in bytes, from the start of the file where to read the data. */ - getUint8(offset: bigint): Promise; + async getUint8(offset: number | bigint): Promise { + const arrayBuffer = await this.file.read(offset, 1); + const val = new Uint8Array(arrayBuffer).at(0); + if (val === undefined) { + throw new Error('something went wrong'); + } + return val; + } /** * Gets an unsigned 16-bit integer at the specified byte offset from the start of the file. * @param offset The offset, in bytes, from the start of the file where to read the data. */ - getUint16(offset: bigint): Promise; + async getUint16(offset: number | bigint): Promise { + const arrayBuffer = await this.file.read(offset, 2); + const val = new Uint16Array(arrayBuffer).at(0); + if (val === undefined) { + throw new Error('something went wrong'); + } + return val; + } /** * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file. - * @param offset The offset, in bytes, from the file of the view where to read the data. + * @param offset The offset, in bytes, from the start of the file where to read the data. */ - getUint32(offset: bigint): Promise; + async getUint32(offset: number | bigint): Promise { + const arrayBuffer = await this.file.read(offset, 4); + const val = new Uint32Array(arrayBuffer).at(0); + if (val === undefined) { + throw new Error('something went wrong'); + } + return val; + } /** * Gets an unsigned 32-bit integer at the specified byte offset from the start of the file. - * @param offset The offset, in byte, from the file of the view where to read the data. + * @param offset The offset, in bytes, from the start of the file where to read the data. */ - getBigUint64(offset: bigint): Promise; + async getBigUint64(offset: number | bigint): Promise { + const arrayBuffer = await this.file.read(offset, 8); + const val = new BigInt64Array(arrayBuffer).at(0); + if (val === undefined) { + throw new Error('something went wrong'); + } + return val; + } /** * returns an ArrayBuffer whose contents are a copy of this file bytes from startOffset, inclusive, up to endOffset, exclusive. - * @param startOffset The offset, in bytes, from the start of the file where to start reading the data. + * @param startOffset The offset, in byte, from the start of the file where to start reading the data. * @param endOffset The offset, in bytes, from the start of the file where to end reading the data. */ - slice(startOffset: bigint, endOffset: bigint): Promise; + async slice(startOffset: bigint | number, endOffset: bigint | number): Promise { + const bigLength = BigInt(endOffset) - BigInt(startOffset); + if (bigLength > Number.MAX_SAFE_INTEGER) { + throw new Error('too big slice'); + } + const length = Number(bigLength); + + return await this.file.read(startOffset, length); + } /** * the length (in bytes) of the data. */ - length: bigint; + get length(): bigint { + return this.size; + } } - -/** - * Check is the object has FileProvider members - * @param fileProvider - tested object - */ -export const isFileProvider = (fileProvider: unknown) => { - return ( - (fileProvider as FileProvider)?.getUint8 && - (fileProvider as FileProvider)?.slice && - (fileProvider as FileProvider)?.length - ); -}; diff --git a/modules/loader-utils/test/index.ts b/modules/loader-utils/test/index.ts index c4c819e8aa..73353c6a29 100644 --- a/modules/loader-utils/test/index.ts +++ b/modules/loader-utils/test/index.ts @@ -22,5 +22,6 @@ import './lib/request-utils/request-scheduler.spec'; import './lib/file-provider/data-view-file.spec'; import './lib/file-provider/file-handle-file.spec'; +import './lib/file-provider/file-provider.spec'; import './lib/worker-loader-utils/parse-with-worker.spec'; diff --git a/modules/loader-utils/test/lib/file-provider/file-provider.spec.ts b/modules/loader-utils/test/lib/file-provider/file-provider.spec.ts new file mode 100644 index 0000000000..bda0ac3095 --- /dev/null +++ b/modules/loader-utils/test/lib/file-provider/file-provider.spec.ts @@ -0,0 +1,40 @@ +import test from 'tape-promise/tape'; +import {DATA_ARRAY} from '@loaders.gl/i3s/test/data/test.zip'; +import {BlobFile, FileProvider} from '@loaders.gl/loader-utils'; + +export const getSignature = () => new Uint8Array([0x50, 0x4b, 0x03, 0x04]); + +const getProvider = () => { + return FileProvider.create(new BlobFile(DATA_ARRAY.buffer)); +}; + +test('FileProvider#slice', async (t) => { + const provider = await getProvider(); + const slice = await provider.slice(0, 4); + t.deepEqual(new Uint8Array(slice), getSignature()); + t.end(); +}); + +test('FileProvider#getUint8', async (t) => { + const provider = await getProvider(); + t.equals(await provider.getUint8(0), 80); + t.end(); +}); + +test('FileProvider#getUint16', async (t) => { + const provider = await getProvider(); + t.equals(await provider.getUint16(0), 19280); + t.end(); +}); + +test('FileProvider#getUint32', async (t) => { + const provider = await getProvider(); + t.equals(await provider.getUint32(0), 67324752); + t.end(); +}); + +test('FileProvider#getBigUint64', async (t) => { + const provider = await getProvider(); + t.equals(await provider.getBigUint64(0), 563035920091984n); + t.end(); +}); diff --git a/modules/tile-converter/src/i3s-converter/helpers/load-3d-tiles.ts b/modules/tile-converter/src/i3s-converter/helpers/load-3d-tiles.ts index 782ad69056..f59c4b07b0 100644 --- a/modules/tile-converter/src/i3s-converter/helpers/load-3d-tiles.ts +++ b/modules/tile-converter/src/i3s-converter/helpers/load-3d-tiles.ts @@ -6,7 +6,7 @@ import type { } from '@loaders.gl/3d-tiles'; import {Tiles3DArchive} from '@loaders.gl/3d-tiles'; import {LoaderWithParser, load} from '@loaders.gl/core'; -import {FileHandleFile, FileProvider} from '@loaders.gl/loader-utils'; +import {FileHandleFile, FileProviderInterface} from '@loaders.gl/loader-utils'; import { CD_HEADER_SIGNATURE, ZipFileSystem, @@ -142,7 +142,7 @@ export function isNestedTileset(tile: Tiles3DTileJSONPostprocessed) { * @returns hash table of the 3TZ file content or undefined if the hash file is not presented inside */ async function loadHashTable( - fileProvider: FileProvider + fileProvider: FileProviderInterface ): Promise> { let hashTable: undefined | Record; diff --git a/modules/zip/src/filesystems/IndexedArchive.ts b/modules/zip/src/filesystems/IndexedArchive.ts index 11cad863f6..4046f7d4d8 100644 --- a/modules/zip/src/filesystems/IndexedArchive.ts +++ b/modules/zip/src/filesystems/IndexedArchive.ts @@ -1,4 +1,4 @@ -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; import {ZipFileSystem} from './zip-filesystem'; /** @@ -6,7 +6,7 @@ import {ZipFileSystem} from './zip-filesystem'; * a hash file inside that allows to increase reading speed */ export abstract class IndexedArchive { - public fileProvider: FileProvider; + public fileProvider: FileProviderInterface; public fileName?: string; /** @@ -15,7 +15,11 @@ export abstract class IndexedArchive { * @param hashTable - pre-loaded hashTable. If presented, getFile will skip reading the hash file * @param fileName - name of the archive. It is used to add to an URL of a loader context */ - constructor(fileProvider: FileProvider, hashTable?: Record, fileName?: string) { + constructor( + fileProvider: FileProviderInterface, + hashTable?: Record, + fileName?: string + ) { this.fileProvider = fileProvider; this.fileName = fileName; } diff --git a/modules/zip/src/filesystems/zip-filesystem.ts b/modules/zip/src/filesystems/zip-filesystem.ts index 54bb374121..d50dbd37fb 100644 --- a/modules/zip/src/filesystems/zip-filesystem.ts +++ b/modules/zip/src/filesystems/zip-filesystem.ts @@ -3,7 +3,7 @@ // Copyright (c) vis.gl contributors import {FileSystem, isBrowser} from '@loaders.gl/loader-utils'; -import {FileProvider, isFileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface, isFileProvider} from '@loaders.gl/loader-utils'; import {FileHandleFile} from '@loaders.gl/loader-utils'; import {ZipCDFileHeader, makeZipCDHeaderIterator} from '../parse-zip/cd-file-header'; import {parseZipLocalFileHeader} from '../parse-zip/local-file-header'; @@ -29,7 +29,7 @@ export const ZIP_COMPRESSION_HANDLERS: {[key: number]: CompressionHandler} = { */ export class ZipFileSystem implements FileSystem { /** FileProvider instance promise */ - public fileProvider: FileProvider | null = null; + public fileProvider: FileProviderInterface | null = null; public fileName?: string; public archive: IndexedArchive | null = null; @@ -37,7 +37,7 @@ export class ZipFileSystem implements FileSystem { * Constructor * @param file - instance of FileProvider or file path string */ - constructor(file: FileProvider | IndexedArchive | string) { + constructor(file: FileProviderInterface | IndexedArchive | string) { // Try to open file in NodeJS if (typeof file === 'string') { this.fileName = file; diff --git a/modules/zip/src/hash-file-utility.ts b/modules/zip/src/hash-file-utility.ts index 8343cfb2ca..5c44000bce 100644 --- a/modules/zip/src/hash-file-utility.ts +++ b/modules/zip/src/hash-file-utility.ts @@ -4,7 +4,7 @@ import {MD5Hash} from '@loaders.gl/crypto'; import { - FileProvider, + FileProviderInterface, concatenateArrayBuffers, concatenateArrayBuffersFromArray } from '@loaders.gl/loader-utils'; @@ -42,7 +42,7 @@ function bufferToHex(buffer: ArrayBuffer, start: number, length: number): string * @returns ready to use hash info */ export async function makeHashTableFromZipHeaders( - fileProvider: FileProvider + fileProvider: FileProviderInterface ): Promise> { const zipCDIterator = makeZipCDHeaderIterator(fileProvider); return getHashTable(zipCDIterator); diff --git a/modules/zip/src/parse-zip/cd-file-header.ts b/modules/zip/src/parse-zip/cd-file-header.ts index 72b97f1f01..c220f93fca 100644 --- a/modules/zip/src/parse-zip/cd-file-header.ts +++ b/modules/zip/src/parse-zip/cd-file-header.ts @@ -4,7 +4,7 @@ import { DataViewFile, - FileProvider, + FileProviderInterface, compareArrayBuffers, concatenateArrayBuffers } from '@loaders.gl/loader-utils'; @@ -66,7 +66,7 @@ export const signature: ZipSignature = new Uint8Array([0x50, 0x4b, 0x01, 0x02]); */ export const parseZipCDFileHeader = async ( headerOffset: bigint, - file: FileProvider + file: FileProviderInterface ): Promise => { if (headerOffset >= file.length) { return null; @@ -127,7 +127,7 @@ export const parseZipCDFileHeader = async ( * @param fileProvider - file provider that provider random access to the file */ export async function* makeZipCDHeaderIterator( - fileProvider: FileProvider + fileProvider: FileProviderInterface ): AsyncIterable { const {cdStartOffset, cdByteSize} = await parseEoCDRecord(fileProvider); const centralDirectory = new DataViewFile( diff --git a/modules/zip/src/parse-zip/end-of-central-directory.ts b/modules/zip/src/parse-zip/end-of-central-directory.ts index b1a4fa9fac..eb1a9a3c83 100644 --- a/modules/zip/src/parse-zip/end-of-central-directory.ts +++ b/modules/zip/src/parse-zip/end-of-central-directory.ts @@ -2,7 +2,11 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {FileProvider, compareArrayBuffers, concatenateArrayBuffers} from '@loaders.gl/loader-utils'; +import { + FileProviderInterface, + compareArrayBuffers, + concatenateArrayBuffers +} from '@loaders.gl/loader-utils'; import {ZipSignature, searchFromTheEnd} from './search-from-the-end'; import {setFieldToNumber} from './zip64-info-generation'; @@ -64,7 +68,7 @@ const ZIP64_COMMENT_OFFSET = 56n; * @param file - FileProvider instance * @returns Info from the header */ -export const parseEoCDRecord = async (file: FileProvider): Promise => { +export const parseEoCDRecord = async (file: FileProviderInterface): Promise => { const zipEoCDOffset = await searchFromTheEnd(file, eoCDSignature); let cdRecordsNumber = BigInt(await file.getUint16(zipEoCDOffset + CD_RECORDS_NUMBER_OFFSET)); diff --git a/modules/zip/src/parse-zip/local-file-header.ts b/modules/zip/src/parse-zip/local-file-header.ts index d0e2cc178f..bee87bbbc3 100644 --- a/modules/zip/src/parse-zip/local-file-header.ts +++ b/modules/zip/src/parse-zip/local-file-header.ts @@ -2,7 +2,11 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {FileProvider, compareArrayBuffers, concatenateArrayBuffers} from '@loaders.gl/loader-utils'; +import { + FileProviderInterface, + compareArrayBuffers, + concatenateArrayBuffers +} from '@loaders.gl/loader-utils'; import {ZipSignature} from './search-from-the-end'; import {createZip64Info, setFieldToNumber} from './zip64-info-generation'; @@ -43,7 +47,7 @@ export const signature: ZipSignature = new Uint8Array([0x50, 0x4b, 0x03, 0x04]); */ export const parseZipLocalFileHeader = async ( headerOffset: bigint, - file: FileProvider + file: FileProviderInterface ): Promise => { const mainHeader = new DataView(await file.slice(headerOffset, headerOffset + FILE_NAME_OFFSET)); diff --git a/modules/zip/src/parse-zip/search-from-the-end.ts b/modules/zip/src/parse-zip/search-from-the-end.ts index 10ec2f813b..46273edacd 100644 --- a/modules/zip/src/parse-zip/search-from-the-end.ts +++ b/modules/zip/src/parse-zip/search-from-the-end.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: MIT // Copyright (c) vis.gl contributors -import {FileProvider} from '@loaders.gl/loader-utils'; +import {FileProviderInterface} from '@loaders.gl/loader-utils'; /** Description of zip signature type */ export type ZipSignature = Uint8Array; @@ -16,7 +16,7 @@ const buffLength = 1024; * @returns */ export const searchFromTheEnd = async ( - file: FileProvider, + file: FileProviderInterface, target: ZipSignature ): Promise => { const searchWindow = [