karl- / pb_Stl

STL import/export for Unity, supporting both ASCII and Binary.
MIT License
179 stars 43 forks source link

Convert ImportBinary() method to use an byte[] #7

Closed jvhgamer closed 5 years ago

jvhgamer commented 6 years ago

using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { using (BinaryReader br = new BinaryReader(fs, new ASCIIEncoding())) { while (br.BaseStream.Position < br.BaseStream.Length) { } } }

Would it be as simple as changing this piece to

using (BinaryWriter bw = new BinaryWriter(new MemoryStream())) { bw.Write( byteArray here ); using (BinaryReader br = new BinaryReader(bw.BaseStream, new ASCIIEncoding())) { while (br.BaseStream.Position < br.BaseStream.Length) { } } }

jvhgamer commented 6 years ago

Confirmed! Had to add in one line. br.BaseStream.Position = 0; after creating the BinaryReader to ensure it started at its initial position.