/// <summary> /// Load the picture data from the file, /// if not done yet. /// </summary> public void Load() { // Already loaded ? if (file == null) { return; } // Load the picture from the stream Stream stream = null; ByteVector data = null; try { if (stream_size == 0) { data = new ByteVector(); } else if (stream_size > 0) { stream = file.ReadStream; stream.Seek(stream_offset, SeekOrigin.Begin); int count = 0, read = 0, needed = (int)stream_size; byte[] buffer = new byte[needed]; do { count = stream.Read(buffer, read, needed); read += count; needed -= count; } while (needed > 0 && count != 0); data = new ByteVector(buffer, read); } else { stream = file.ReadStream; stream.Seek(stream_offset, SeekOrigin.Begin); data = ByteVector.FromStream(stream); } } finally { // Free the resources if (stream != null && file != null) { file.CloseStream(stream); } file = null; } // Decode the raw data if required, by using FieldData raw_data = FieldData(data, -(int)FrameHeader.Size(raw_version), raw_version); // Get the actual data ParseRawData(); }
internal static ByteVector FromFile(File.IFileAbstraction abstraction, out byte[] firstChunk, bool copyFirstChunk) { if (abstraction == null) { throw new ArgumentNullException("abstraction"); } System.IO.Stream stream = abstraction.ReadStream; ByteVector output = FromStream(stream, out firstChunk, copyFirstChunk); abstraction.CloseStream(stream); return(output); }
/// <summary> /// Load the picture data from the file, /// if not done yet. /// </summary> public void Load() { // Already loaded ? if (data != null) { return; } // Load the picture from the stream Stream stream = null; try { if (stream_size == 0) { data = new ByteVector(); } else if (stream_size > 0) { stream = file.ReadStream; stream.Seek(stream_offset, SeekOrigin.Begin); int count = 0, read = 0, needed = (int)stream_size; byte[] buffer = new byte[needed]; do { count = stream.Read(buffer, read, needed); read += count; needed -= count; } while (needed > 0 && count != 0); data = new ByteVector(buffer, read); } else { stream = file.ReadStream; stream.Seek(stream_offset, SeekOrigin.Begin); data = ByteVector.FromStream(stream); } } finally { // Free the resources if (stream != null && file != null) { file.CloseStream(stream); } file = null; } // Retrieve remaining properties from data (if required) if (mime_type == null) { string ext = Picture.GetExtensionFromData(data); MimeType = Picture.GetMimeFromExtension(ext); if (ext != null) { type = PictureType.FrontCover; if (filename == null) { filename = description = "cover" + ext; } } else { type = PictureType.NotAPicture; if (filename == null) { filename = "UnknownType"; } } } }