-
Notifications
You must be signed in to change notification settings - Fork 196
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
fix(loader-utils): ReadableFile implementation to match the interface #3157
Conversation
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change?
There was a problem hiding this comment.
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
async read(offset?: number | bigint, length?: number): Promise<ArrayBuffer> { | ||
const response = await this.fetchRange(offset ?? 0, length ?? 0); |
There was a problem hiding this comment.
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?
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> { |
There was a problem hiding this comment.
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
andoffset
? - How does this function now know where to stop reading?
- Should it be
length
instead?
There was a problem hiding this comment.
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
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 needBlobFile
for it