Skip to content

Commit

Permalink
Add stream constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
Kermalis committed Oct 4, 2020
1 parent 4772c0f commit 9af27eb
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions DLS2/DLS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,28 @@ public DLS(string path)
{
using (var reader = new EndianBinaryReader(File.Open(path, FileMode.Open)))
{
string str = reader.ReadString(4, false);
if (str != "RIFF")
{
throw new InvalidDataException("RIFF header was not found at the start of the file.");
}
uint size = reader.ReadUInt32();
str = reader.ReadString(4, false);
if (str != "DLS ")
{
throw new InvalidDataException("DLS header was not found at the expected offset.");
}
_chunks = DLSChunk.GetAllChunks(reader, reader.BaseStream.Position + (size - 4)); // Subtract 4 for the "DLS "
_chunks = Init(reader);
}
}
public DLS(Stream stream)
{
_chunks = Init(new EndianBinaryReader(stream));
}
private List<DLSChunk> Init(EndianBinaryReader reader)
{
string str = reader.ReadString(4, false);
if (str != "RIFF")
{
throw new InvalidDataException("RIFF header was not found at the start of the file.");
}
uint size = reader.ReadUInt32();
long endOffset = reader.BaseStream.Position + size;
str = reader.ReadString(4, false);
if (str != "DLS ")
{
throw new InvalidDataException("DLS header was not found at the expected offset.");
}
return DLSChunk.GetAllChunks(reader, endOffset);
}

public void UpdateCollectionHeader()
Expand Down

0 comments on commit 9af27eb

Please sign in to comment.