Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loader-utils): ReadableFile implementation to match the interface #3157

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

dariaterekhova-actionengine
Copy link
Collaborator

Changing input types of ReadableFile implementations to match the interface. Currently it's not matched and that cause runtime errors. I need this change because I'm currently working on local slpk reading for I3S explorer and I need BlobFile for it

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I faced a problem when I have ReadableFile as input in FileProvider and read() there accepts start as number | bigint so I pass bigint here and get runtime error that it cannot sum bigint and number because real implementation knows nothing about bigint. We need keep real implementation of the methods matching it's description in ReadableFile

Comment on lines 33 to 34
async read(offset?: number | bigint, length?: number): Promise<ArrayBuffer> {
const response = await this.fetchRange(offset ?? 0, length ?? 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use default argument syntax for better clarity?

Suggested change
async read(offset?: number | bigint, length?: number): Promise<ArrayBuffer> {
const response = await this.fetchRange(offset ?? 0, length ?? 0);
async read(offset: number | bigint = 0, length: number = 0): Promise<ArrayBuffer> {
const response = await this.fetchRange(offset, length);

@@ -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, offset?: number): Promise<ArrayBuffer> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • What is the difference between start and offset?
  • How does this function now know where to stop reading?
  • Should it be length instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's my mistake, I'll change it to length, as it's in the ReadableFile and NodeFile implementation

@dariaterekhova-actionengine dariaterekhova-actionengine merged commit e1e04ff into master Nov 8, 2024
2 checks passed
@dariaterekhova-actionengine dariaterekhova-actionengine deleted the dt/match_files_with_interface branch November 8, 2024 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants