Skip to content

Commit

Permalink
fix(loader-utils): ReadableFile implementation to match the interface (
Browse files Browse the repository at this point in the history
  • Loading branch information
dariaterekhova-actionengine committed Nov 26, 2024
1 parent cff7926 commit 00b69d5
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 140 deletions.
5 changes: 2 additions & 3 deletions examples/experimental/slpk-in-browser/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import {MapController, FlyToInterpolator, MapViewState} from '@deck.gl/core/type
import {COORDINATE_SYSTEM, I3SLoader, parseSLPKArchive} from '@loaders.gl/i3s';
import {Tileset3D} from '@loaders.gl/tiles';
import {ControlPanel} from './components/control-panel';
import {BrowserFile} from './browser-file';
import {ZipFileSystem} from '@loaders.gl/zip';
import {LoaderWithParser} from '@loaders.gl/loader-utils';
import {BlobFile, FileProvider, LoaderWithParser} from '@loaders.gl/loader-utils';
import CustomTile3DLayer from './custom-tile-3d-layer';

export const TRANSITION_DURAITON = 4000;
Expand Down Expand Up @@ -49,7 +48,7 @@ export default function App() {
}

const createFileSystem = async (file: File) => {
const fileProvider = new BrowserFile(file);
const fileProvider = await FileProvider.create(new BlobFile(file));
const archive = await parseSLPKArchive(fileProvider, undefined, file.name);
const fileSystem = new ZipFileSystem(archive);
setFileSystem(fileSystem);
Expand Down
132 changes: 0 additions & 132 deletions examples/experimental/slpk-in-browser/src/browser-file.ts

This file was deleted.

2 changes: 1 addition & 1 deletion examples/experimental/slpk-in-browser/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getAliases = async (frameworkName, frameworkRootDir) => {

// https://vitejs.dev/config/
export default defineConfig(async () => ({
resolve: {alias: await getAliases('@loaders.gl', `${__dirname}/../../..`)},
resolve: {alias: await getAliases('@loaders.gl', `${__dirname}/../..`)},
server: {open: true}
}))

6 changes: 4 additions & 2 deletions modules/loader-utils/src/lib/files/blob-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ export class BlobFile implements ReadableFile {
};
}

async read(start: number, length: number): Promise<ArrayBuffer> {
const arrayBuffer = await this.handle.slice(start, start + length).arrayBuffer();
async read(start?: number | bigint, length?: number): Promise<ArrayBuffer> {
const arrayBuffer = await this.handle
.slice(Number(start), Number(start) + Number(length))
.arrayBuffer();
return arrayBuffer;
}
}
2 changes: 1 addition & 1 deletion modules/loader-utils/src/lib/files/http-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class HttpFile implements ReadableFile {
};
}

async read(offset: number | bigint, length: number): Promise<ArrayBuffer> {
async read(offset: number | bigint = 0, length: number = 0): Promise<ArrayBuffer> {
const response = await this.fetchRange(offset, length);
const arrayBuffer = await response.arrayBuffer();
return arrayBuffer;
Expand Down
2 changes: 1 addition & 1 deletion modules/loader-utils/src/lib/files/node-file-facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class NodeFileFacade implements ReadableFile, WritableFile {
throw new Error('Can\'t instantiate NodeFile. Make sure to import @loaders.gl/polyfills first.');
}
/** Read data */
async read(start?: number | bigint, end?: number | bigint): Promise<ArrayBuffer> {
async read(start?: number | bigint, length?: number): Promise<ArrayBuffer> {
throw NOT_IMPLEMENTED;
}
/** Write to file. The number of bytes written will be returned */
Expand Down

0 comments on commit 00b69d5

Please sign in to comment.