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

Seek support on read operations #86

Open
tomfite opened this issue Jul 20, 2020 · 1 comment
Open

Seek support on read operations #86

tomfite opened this issue Jul 20, 2020 · 1 comment

Comments

@tomfite
Copy link

tomfite commented Jul 20, 2020

I'm implementing a service using reactphp/filesystem that allows for data transfer supporting resume operations. In order to accomplish this, I need to be able to seek() to a particular offset in the file.

I've found that the Adapter::read method contains a reference to the offset, passed in as the third parameter.

    public function read($fileDescriptor, $length, $offset)
    {
        return $this->fileDescriptors[$fileDescriptor]->rpc(Factory::rpc('read', [
            'length' => $length,
            'offset' => $offset,
        ]))->then(function ($payload) {
            return \React\Promise\resolve(base64_decode($payload['chunk']));
        });
    }

However, this $offset seems to only be used internally by the ReadableStreamTrait class, by keeping a reference to the current readCursor and incrementing this by chunkSize each read operation.

Is there any way to set the reacCursor position manually or do I need to look into using the Adapter / filesystem class directly? Would it be worth adding a new method to the ReadableStreamTrait to set the readCursor directly in order to set the offset?

@clue
Copy link
Member

clue commented Aug 4, 2020

@tomfite Thanks for reporting, I agree this should be supported and exposed by our APIs! 👍

It looks like this is exposed by AdapterInterface::read() and AdapterInterface::getContents() recently introduced via #62, but not FilesystemInterface::getContents(). This means you should be able to pass this offset to seek to a specific position already. We're working towards more consistent APIs with #46, PRs to help with this are always very much appreciated! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants