/// <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 async Task <ZipStorer> Open(IZipStorerProvider _Provider, string _filename, bool isWriteAccess) { Stream stream = await _Provider.File_OpenStream(_filename, isWriteAccess); //new FileStream(_filename, FileMode.Open, _access == FileAccess.Read ? FileAccess.Read : FileAccess.ReadWrite); ZipStorer zip = Open(_Provider, stream, isWriteAccess); zip.FileName = _filename; return(zip); }
/// <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 ZipStorer Create(IZipStorerProvider _Provider, Stream _stream, string _comment = "") { ZipStorer zip = new ZipStorer(); zip.Provider = _Provider; zip.Comment = _comment; zip.ZipFileStream = _stream; zip.IsWriteAccess = true; 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 async static Task <ZipStorer> Create(IZipStorerProvider _Provider, string _filename, string _comment = "") { Stream stream = await _Provider.File_CreateStream(_filename); //new FileStream(_filename, FileMode.Create, FileAccess.ReadWrite); ZipStorer zip = Create(_Provider, 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 ZipStorer Open(IZipStorerProvider _Provider, Stream _stream, bool isWriteAccess) { if (!_stream.CanSeek && !isWriteAccess) { throw new InvalidOperationException("Stream cannot seek"); } ZipStorer zip = new ZipStorer(); zip.Provider = _Provider; //zip.FileName = _filename; zip.ZipFileStream = _stream; zip.IsWriteAccess = isWriteAccess; if (zip.ReadFileInfo()) { return(zip); } throw new System.IO.InvalidDataException(); }