digitalmars.D.learn - reading from a ubyte[] | byte[] as if from a stream? (Phobos)
- Charles Hixson (7/7) Sep 18 2008 Is it possible to read from a byte or ubyte array as if from a stream?
- BCS (3/12) Sep 18 2008 MemoryStream
- Tomas Lindquist Olsen (3/19) Sep 18 2008 From what I read, MemoryStream copies, TArrayStream does not
- Charles Hixson (9/29) Sep 18 2008 Thanks to the both!
- Tomas Lindquist Olsen (10/18) Sep 18 2008 Now, I don't use phobos, but I think you're looking for std.stream.TArra...
Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.
Sep 18 2008
Reply to Charles,Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.MemoryStream http://www.digitalmars.com/d/1.0/phobos/std_stream.html
Sep 18 2008
BCS wrote:Reply to Charles,From what I read, MemoryStream copies, TArrayStream does not Not sure what's wanted here though :)Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.MemoryStream http://www.digitalmars.com/d/1.0/phobos/std_stream.html
Sep 18 2008
Tomas Lindquist Olsen wrote:BCS wrote:Thanks to the both! TArrayStream would be what I want, except that it seems to require that the compilation be in release mode. I'm going to need to study just what that means. But if it isn't what's needed, then MemoryStream seems a reasonable alternative. (My suspicion is that it only constructs an array of bytes of memory if you don't pass it a buffer...but I haven't checked. The documentation sure seems to say that it copies the buffer.)Reply to Charles,From what I read, MemoryStream copies, TArrayStream does not Not sure what's wanted here though :)Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.MemoryStream http://www.digitalmars.com/d/1.0/phobos/std_stream.html
Sep 18 2008
Charles Hixson wrote:Is it possible to read from a byte or ubyte array as if from a stream? It looks like it should be not only possible, but easy...but I haven't figured it out. BufferedFile *MUST* do that kind of thing internally, but it feels like there ought to be a way to say "This array is your data, read from it!" rather than digging through the guts of it and copying all the relevant code into a separate code-space.Now, I don't use phobos, but I think you're looking for std.stream.TArrayStream something like: --- auto data = new ubyte[1024]; auto str = new TArrayStream!(ubyte[])(data); ubyte ub; str.read(ub); --- HTH
Sep 18 2008