Skip to content

[Help] What is the difference between Source and RawSource? #443

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

Closed
masterQian opened this issue Apr 1, 2025 · 2 comments
Closed

[Help] What is the difference between Source and RawSource? #443

masterQian opened this issue Apr 1, 2025 · 2 comments
Labels

Comments

@masterQian
Copy link

masterQian commented Apr 1, 2025

What is the difference between Source and RawSource?
There is no document to tell me, it's too obscure and difficult to understand.
When I use SystemFileSystem, I get RawSource, but when I get and process byte arrays, only Source has a read method.
If I need to provide an input source, should the parameter passed during the function call be RawSource or Source?
which step does the time-consuming data reading occur? Where should I use withContext to switch coroutines to IO Dispatcher?
At the step where SystemFileSystem retrieves RawSource?
At it happen at the RawSource.buffered() ?
At the Source.readByteArray()?

Thanks !!!!!

@fzhinkin
Copy link
Collaborator

fzhinkin commented Apr 1, 2025

@masterQian, Source is a buffered version of RawSource, you can check the documentation, the differences are elaborated there:

Please let me know if you think there are parts of these docs that are not clear and should be improved to better elaborate the difference and use-cases.

The actual IO won't happen until you read something from Source, so in terms of blocking, it makes sense to schedule Source.readByteArray() call into a separate coroutine. However, note that primitives provided by the library are not thread-safe, so proper synchronization will be required if you decide to use the source concurrently.

@masterQian
Copy link
Author

@fzhinkin Thank you very much for your answer!

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

No branches or pull requests

2 participants