Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is possible.</p> <p>You should make it a binary (non-human-readable) file, and use the <code>BinaryWriter</code> and <code>BinaryReader</code> classes to read and write the lengths.</p> <p>You can read a file from it like this:</p> <pre><code>using (FileStream combinedFile = File.Open(...)) using (var binReader = new BinaryReader(combinedFile)) { while(!combinedFile.EOF) { long segmentLength = binReader.ReadInt64(); var bytes = new byte[segmentLength]; long totalRead = 0; while(bytesRead &lt; segmentLength) { int read = combinedFile.Read(bytes, totalRead, Math.Min(4096, segmentLength - totalRead)); if (read == 0) throw new InvalidDataException(); } yield return new MemoryStream(bytes); } } </code></pre> <p><strong>EDIT</strong> To make a human-readable file, write the segment length as a fixed-length string (padded to some reasonable number of digits, such as 16), optionally followed by a newline. The maximum segment size is the length of the string.</p> <p>You can read a file from it like this:</p> <pre><code>const int LengthPadding = 16 using (FileStream combinedFile = File.Open(...)) using (var binReader = new BinaryReader(combinedFile)) { while(!combinedFile.EOF) { char[] segmentLengthChars = binReader.ReadChars(16); long segmentLength = long.Parse(new string(segmentLengthChars)); binReader.ReadChars(2); //Skip the newline var bytes = new byte[segmentLength]; long totalRead = 0; while(bytesRead &lt; segmentLength) { int read = combinedFile.Read(bytes, totalRead, Math.Min(4096, segmentLength - totalRead)); if (read == 0) throw new InvalidDataException(); } yield return new MemoryStream(bytes); } } </code></pre> <p>To write the segment length, call</p> <pre><code>binWriter.WriteChars(length.ToString().PadLeft(16, '0').ToCharArray()); binWriter.WriteChars(new char[] { '\r', '\n' }); </code></pre> <p>You should explicitly pass an encoding and <code>CultureInfo.InvariantCulture</code> where applicable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload