public bool SeekBehind(long count) { if (count < 0) { Logger.FATAL("Invali count"); return(false); } if (DataStream.Position < count) { Logger.FATAL("End of file will be reached"); return(false); } try { DataStream.Seek(-count, SeekOrigin.Current); } catch (Exception ex) { Logger.FATAL("Unable to seek behind {0} bytes {1}", count, ex.Message); return(false); } return(true); }
public bool SeekTo(long p) { try { DataStream.Seek(p, SeekOrigin.Begin); } catch (Exception ex) { Logger.FATAL($"Unable to seek to position {p} {ex.Message}"); return(false); } return(true); }
public bool ReadBuffer(byte[] pBuffer, int offset = 0, int count = 0) { try { DataStream.Read(pBuffer, offset, count == 0 ? pBuffer.Length - offset : count); } catch (Exception ex) { Logger.FATAL("can't read buffer from {0} {1}", FileName, ex.Message); return(false); } return(true); }
public static MediaFile Initialize(string path, FileMode fileMode = FileMode.Open, FileAccess fileAccess = FileAccess.Read) { try { Stream dataStream = new FileStream(path, fileMode, fileAccess); return(new MediaFile(path) { DataStream = dataStream, Br = fileAccess != FileAccess.Write?new N2HBinaryReader(dataStream):null, Bw = fileAccess != FileAccess.Read?new H2NBinaryWriter(dataStream) : null }); } catch (Exception ex) { Logger.FATAL("{0}", ex); return(null); } }
public static MediaFile CacheMediaFile(string path, FileAccess fileAccess = FileAccess.Read) { try { var fileStream = new FileStream(path, FileMode.Open, fileAccess); var dataStream = new MemoryStream(); fileStream.CopyTo(dataStream); dataStream.Position = 0; fileStream.Dispose(); return(new MediaFile(path) { DataStream = dataStream, Br = fileAccess != FileAccess.Write ? new N2HBinaryReader(dataStream) : null, Bw = fileAccess != FileAccess.Read ? new H2NBinaryWriter(dataStream) : null }); } catch (Exception ex) { Logger.FATAL("{0}", ex); return(null); } }