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

loadBytes on Resource #42

Closed
JakubKahovec opened this issue Nov 1, 2015 · 4 comments
Closed

loadBytes on Resource #42

JakubKahovec opened this issue Nov 1, 2015 · 4 comments
Labels

Comments

@JakubKahovec
Copy link

Hi,

First thank you for your library it makes life working with files much easier :-)
So what would be the recommended way (without converting char to byte) to get bytes from a resource (fetched through resource"/myresource.json") as loadBytes only exist on File class

Thanks

Jakub

@pathikrit
Copy link
Owner

Hi, yes, the Resource APIs are not done yet. Future versions of better-files would have resource APIs similar to the files.

For now, I think this would work using better-files:

val bytes: Iterator[Byte] = this.getClass.getResourceAsStream("myresource.json").bytes

Duplicate of #9

@pathikrit
Copy link
Owner

See:

def bytes: Iterator[Byte] = in.autoClosedIterator(_.read())(_ != eof).map(_.toByte)

@JakubKahovec
Copy link
Author

Works fine, thank you.

On 2 November 2015 at 03:44, Pathikrit Bhowmick notifications@github.com
wrote:

See:

def bytes: Iterator[Byte] = in.autoClosedIterator(_.read())(_ != eof).map(_.toByte)


Reply to this email directly or view it on GitHub
#42 (comment)
.

@pathikrit
Copy link
Owner

Forgot to mention, you might want .buffered.bytes for large files..

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