/// <summary> /// Method to create a new zip storage in a stream /// </summary> /// <param name="_stream"></param> /// <param name="_comment"></param> /// <returns>A valid ZipStorer object</returns> public static VDataProcesser Create(XorStream _stream, string _comment) { VDataProcesser zip = new VDataProcesser(); zip.Comment = _comment; zip.ZipFileStream = _stream; zip.Access = FileAccess.Write; return(zip); }
/// <summary> /// Method to open an existing storage file /// </summary> /// <param name="_filename">Full path of Zip file to open</param> /// <param name="_access">File access mode as used in FileStream constructor</param> /// <returns>A valid ZipStorer object</returns> public static VDataProcesser Open(string _filename, FileAccess _access) { var stream = new XorStream(_filename, FileMode.Open, _access == FileAccess.Read ? FileAccess.Read : FileAccess.ReadWrite); VDataProcesser zip = Open(stream, _access); zip.FileName = _filename; return(zip); }
/// <summary> /// Method to create a new storage file /// </summary> /// <param name="_filename">Full path of Zip file to create</param> /// <param name="_comment">General comment for Zip file</param> /// <returns>A valid ZipStorer object</returns> public static VDataProcesser Create(string _filename, string _comment) { var stream = new XorStream(_filename, FileMode.Create, FileAccess.ReadWrite); VDataProcesser zip = Create(stream, _comment); zip.Comment = _comment; zip.FileName = _filename; return(zip); }
/// <summary> /// Method to open an existing storage from stream /// </summary> /// <param name="_stream">Already opened stream with zip contents</param> /// <param name="_access">File access mode for stream operations</param> /// <returns>A valid ZipStorer object</returns> public static VDataProcesser Open(XorStream _stream, FileAccess _access) { if (!_stream.CanSeek && _access != FileAccess.Read) { throw new InvalidOperationException("Stream cannot seek"); } VDataProcesser zip = new VDataProcesser(); //zip.FileName = _filename; zip.ZipFileStream = _stream; zip.Access = _access; if (zip.ReadFileInfo()) { return(zip); } throw new System.IO.InvalidDataException(); }
/// <summary> /// Updates central directory (if pertinent) and close the Zip storage /// </summary> /// <remarks>This is a required step, unless automatic dispose is used</remarks> public void Close() { if (this.Access != FileAccess.Read) { uint centralOffset = (uint)this.ZipFileStream.Position; uint centralSize = 0; if (this.CentralDirImage != null) { this.ZipFileStream.Write(CentralDirImage, 0, CentralDirImage.Length); } for (int i = 0; i < Files.Count; i++) { long pos = this.ZipFileStream.Position; this.WriteCentralDirRecord(Files[i]); centralSize += (uint)(this.ZipFileStream.Position - pos); } if (this.CentralDirImage != null) { this.WriteEndRecord(centralSize + (uint)CentralDirImage.Length, centralOffset); } else { this.WriteEndRecord(centralSize, centralOffset); } } if (this.ZipFileStream != null) { this.ZipFileStream.Flush(); this.ZipFileStream.Dispose(); this.ZipFileStream = null; } }