Request - Write / Read from memory
-
- Posts: 22
- Joined: Thu Nov 13, 2014 9:05 pm
Request - Write / Read from memory
It's not always you want to write to or read from file. Sometimes you want to write directly into memory. For example, if you want to save an encrypted file, you might first want to write those bytes into memory, then write the encrypted representation of those onto disk.
Re: Request - Write / Read from memory
Hi there,
This is already possible. Simply set the save location to Memory when creating your ES2Writer/Reader, and you can use writer.stream.ReadAllBytes() to get the contents of the writer.
All the best,
Joel
This is already possible. Simply set the save location to Memory when creating your ES2Writer/Reader, and you can use writer.stream.ReadAllBytes() to get the contents of the writer.
All the best,
Joel
-
- Posts: 22
- Joined: Thu Nov 13, 2014 9:05 pm
Re: Request - Write / Read from memory
Awesome, I must have missed that. Couldn't find anything in the docs but maybe I didn't look hard enough.
-
- Posts: 22
- Joined: Thu Nov 13, 2014 9:05 pm
Re: Request - Write / Read from memory
Can you show an explicit example how this is used? I'm having trouble getting it to work. I can't find any stream property of ES2Writer instance, and I can't find anything in the docs.
What I want to do is write to memory, and then read all that from memory into ES2Data.
What I want to do is write to memory, and then read all that from memory into ES2Data.
Re: Request - Write / Read from memory
Hi there,
The writer.stream is currently undocumented as it's only used internally, so it won't show up in code completion, but it is there. i.e.
Joel
The writer.stream is currently undocumented as it's only used internally, so it won't show up in code completion, but it is there. i.e.
var settings = new ES2Settings(); settings.saveLocation = ES2Settings.SaveLocation.Memory; byte[] bytes; using(var writer = ES2Writer.Create(settings)) { writer.Write(123, "tag1"); writer.Write("myString", "tag2"); bytes = writer.stream.ReadAllBytes(); } using(var reader = new ES2Reader(bytes, settings)) { var es2Data = reader.ReadAll(); }All the best,
Joel
-
- Posts: 22
- Joined: Thu Nov 13, 2014 9:05 pm
Re: Request - Write / Read from memory
Perfect, thanks!
-
- Posts: 22
- Joined: Thu Nov 13, 2014 9:05 pm
Re: Request - Write / Read from memory
Any particular reason ReadAll and these create methods are undocumented?
Last edited by MaximumFirecracker on Thu Dec 29, 2016 6:06 pm, edited 1 time in total.
Re: Request - Write / Read from memory
We've hidden the stream field from the code completion and left it undocumented because it's very easy to cause major problems when traversing the stream directly.
We intend on adding a GetAllBytes() method to the ES2Writer class which will be documented, and at the same time add the documentation for the LoadAll() method. Very few people have actually needed to use this functionality so we've not currently added and documented it, but it's on our To Do list.
All the best,
Joel
We intend on adding a GetAllBytes() method to the ES2Writer class which will be documented, and at the same time add the documentation for the LoadAll() method. Very few people have actually needed to use this functionality so we've not currently added and documented it, but it's on our To Do list.
All the best,
Joel