hoelzro / p6-io-string

IO::String for Perl6
MIT License
4 stars 3 forks source link

Starting a branch for read and write features #3

Closed zostay closed 8 years ago

zostay commented 8 years ago

This is work in progress, but I wanted to submit a pull request to get your feedback.

So far I revamped internals and added support for doing basic reads. Writes work as before (with new internals).

hoelzro commented 8 years ago

@zostay Thanks for working on this! I've left some comments on the code; please have a look when you have time.

zostay commented 8 years ago

I hope to have a chance to look at this after work later. The comments are very helpful.

hoelzro commented 8 years ago

@zostay Excellent, keep me posted. Thanks again for helping to develop IO::String!

zostay commented 8 years ago

I think I addressed each of the suggestions you made. I also added more documentation and tests. I still need to look into what other methods should be implemented to complete the implementation.

hoelzro commented 8 years ago

This looks pretty good; I'll merge later today!

zostay commented 8 years ago

I added one last push and I am done now. This adds readchars(), seek(), and tell() so you can do character counting. I'm not going to implement slurp-rest() and read(), etc. because that involves encoding support.

Writes lack support for seek() and tell(), so print() does not overwrite as it should and put() and friends. That needs to be added to complete read/write support.

zostay commented 8 years ago

So, I broke my promise. I went ahead and fixed print. This adds a :a option to open, makes seek work with print, also adds getc, which I overlooked, adds put, and adds gist and perl methods. It adds more tests for many of these things.

Most of what remains is related to encoding, which I haven't dived into. It wouldn't be hard to add, though. Mostly, it's just a matter of making sure .encode and .decode are called in time to count bytes rather than chars or to write bytes to the string. An IO::Buf might be a nice companion to this object.

hoelzro commented 8 years ago

One quick thought: getc returns Nil at end of stream; should readchars return Nil as well?

hoelzro commented 8 years ago

I'm going to merge to get the ball rolling, but IO::Handle appears to return Str on end of stream.

zostay commented 8 years ago

Thanks for making this happen and sorry I didn't get back to you. It has been a crazy couple of days for me. Anyway, you rock! :+1:

Cheers.