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

SourceCustom requires a pointer in the onRead hook #74

Closed
WojciechSoczynskiTHEY opened this issue Aug 22, 2024 · 3 comments
Closed

SourceCustom requires a pointer in the onRead hook #74

WojciechSoczynskiTHEY opened this issue Aug 22, 2024 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@WojciechSoczynskiTHEY
Copy link

LibVips offers since some time a way to provide a custom source. This is handy since it allows creating adapter for many different input methods e.g S3 byte ranges / streaming.

Unfortunately, the SourceCustom.onRead requires a pointer as the first argument to the handler.

class SourceCustom extends Source {
        onRead: (ptr: number, size: bigint) => bigint;
        onSeek: (offset: bigint, whence: number) => bigint;
    }

The example on https://www.libvips.org/2019/11/29/True-streaming-for-libvips.html that is in Python shows how ideally that should work. Please note that the file here is only for demonstrative purposes and in a real world scenario that would be something completely dufferent.

file = open(sys.argv[1], "rb")

def read_handler(size):
    return file.read(size)

def seek_handler(offset, whence):
    file.seek(offset, whence)
    return file.tell()

source = pyvips.Source()
source.on_read(read_handler)
source.on_seek(seek_handler)
@kleisauke
Copy link
Owner

The arguments align with the read(2) system call. I'm uncertain if we should deviate from this approach. Here's an example to help you get started:
https://gist.github.com/kleisauke/2ee72c6788dfc12b463f10e5b8d6632f

Note that the ReadableStream and WritableStream overlay is still on the roadmap, see: #59 (comment).

@kleisauke kleisauke added this to the v0.0.11 milestone Sep 18, 2024
@kleisauke kleisauke added the enhancement New feature or request label Sep 18, 2024
@kleisauke
Copy link
Owner

Actually, you're right, this is a bit confusing to do in JavaScript. Commit 26aaa0c avoids the need of pointer arguments in these callbacks. I've updated the previous linked gist to reflect this.

This will be in v0.0.11, thanks for reporting this!

@kleisauke
Copy link
Owner

v0.0.11 is now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants