Request - Write / Read from memory

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Request - Write / Read from memory

Post by MaximumFirecracker »

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.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Request - Write / Read from memory

Post by Joel »

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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Request - Write / Read from memory

Post by MaximumFirecracker »

Awesome, I must have missed that. Couldn't find anything in the docs but maybe I didn't look hard enough.
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Request - Write / Read from memory

Post by MaximumFirecracker »

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.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Request - Write / Read from memory

Post by Joel »

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.
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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Request - Write / Read from memory

Post by MaximumFirecracker »

Perfect, thanks! :D
MaximumFirecracker
Posts: 22
Joined: Thu Nov 13, 2014 9:05 pm

Re: Request - Write / Read from memory

Post by MaximumFirecracker »

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.
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Request - Write / Read from memory

Post by Joel »

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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked