private void ProcessData(int blockSize, EntryType entryType, Action <byte[], int> action) { // Allocate buffer var buffer = new byte[blockSize]; // Open stream using (var stream = new FileStream(_fileName, FileMode.Open, FileAccess.Read, FileShare.Read)) { // Only entries of supplied entry type foreach (var entry in Entries.FindAll(e => (entryType & e.Type) == e.Type)) { // Seek to filedata stream.Seek(entry.DataOffset, SeekOrigin.Begin); var partial = new PartialStream(stream, entry.FileSize); int size; // Process data while ((size = partial.Read(buffer, 0, blockSize)) > 0) { // Execute action action(buffer, size); } } } }
private void ExportTexture(IExportContainer container, FileStream fileStream, Texture2D texture) { byte[] buffer = null; if (Texture2D.IsReadStreamData(texture.File.Version)) { string path = texture.StreamData.Path; if (path == string.Empty) { buffer = (byte[])texture.ImageData; } else { if (texture.ImageData.Count != 0) { throw new Exception("Texture contains data and resource path"); } using (ResourcesFile res = texture.File.Collection.FindResourcesFile(texture.File, path)) { using (PartialStream resStream = new PartialStream(res.Stream, res.Offset, res.Size)) { resStream.Position = texture.StreamData.Offset; buffer = new byte[texture.StreamData.Size]; resStream.Read(buffer, 0, buffer.Length); } } } } else { buffer = (byte[])texture.ImageData; } using (Bitmap bitmap = ConvertToBitmap(container, texture, buffer)) { if (bitmap != null) { bitmap.Save(fileStream, ImageFormat.Png); } } }