Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I create a Package on a memory stream

Is it possible to create a System.IO.Packaging.Package on a memory stream. I'd like to avoid the file system and do everything in memory if possible.

However, the only way to create a Package is to call Package.Open which accepts a stream. However, if the stream is empty, this fails.

Any clue?

like image 324
user380719 Avatar asked Sep 01 '10 21:09

user380719


People also ask

How does memory stream work?

MemoryStream encapsulates data stored as an unsigned byte array. The encapsulated data is directly accessible in memory. Memory streams can reduce the need for temporary buffers and files in an application. The current position of a stream is the position at which the next read or write operation takes place.

How do you save on MemoryStream?

Save MemoryStream to a String StreamWriter sw = new StreamWriter(memoryStream); sw. WriteLine("Your string to Memoery"); This string is currently saved in the StreamWriters buffer. Flushing the stream will force the string whose backing store is memory (MemoryStream).

What is the difference between MemoryStream and FileStream?

As the name suggests, a FileStream reads and writes to a file whereas a MemoryStream reads and writes to the memory. So it relates to where the stream is stored.


1 Answers

This works:

Stream memStream = new MemoryStream();
Package pack = Package.Open(memStream, FileMode.Create);
like image 178
Matthew Flaschen Avatar answered Oct 20 '22 17:10

Matthew Flaschen