예제 #1
0
        public void Extract(Stream stream)
        {
            var args = new EntryExtractEventArgs {
                Entry          = this,
                ProcessedSoFar = 0
            };

            OnExtract(args);
            if (!IsDirectory)
            {
                OperationFlags flags = OperationFlags.None;
                IntPtr         file  = IntPtr.Zero;
                try {
                    file = Native.zip_fopen_index(archive.ArchivePointer, Index, flags);
                    if (file == IntPtr.Zero)
                    {
                        throw archive.GetErrorException();
                    }
                    DoExtract(file, stream, args);
                }
                finally {
                    if (file != IntPtr.Zero)
                    {
                        Native.zip_fclose(file);
                    }
                }
            }
            OnExtract(args);
        }
예제 #2
0
 internal void OnEntryExtract(EntryExtractEventArgs args)
 {
     if (EntryExtract == null)
     {
         return;
     }
     EntryExtract(this, args);
 }
예제 #3
0
        void OnExtract(EntryExtractEventArgs args = null)
        {
            if (args == null)
            {
                args = new EntryExtractEventArgs {
                    Entry          = this,
                    ProcessedSoFar = 100                     // One-shot, assuming completion
                };
            }

            archive.OnEntryExtract(args);
        }
예제 #4
0
        void DoExtract(IntPtr zipFile, Stream destinationStream, EntryExtractEventArgs args)
        {
            var buf = new byte [ReadBufSize];

            long nread;

            while ((nread = Native.zip_fread(zipFile, buf, (ulong)buf.Length)) > 0)
            {
                destinationStream.Write(buf, 0, (int)nread);
                args.ProcessedSoFar += (ulong)nread;
                OnExtract(args);
            }
        }
예제 #5
0
        void DoExtract(IntPtr zipFile, Stream destinationStream, EntryExtractEventArgs args)
        {
            var buf = ArrayPool <byte> .Shared.Rent(ReadBufSize);

            try {
                long nread;
                while ((nread = Native.zip_fread(zipFile, buf, (ulong)buf.Length)) > 0)
                {
                    destinationStream.Write(buf, 0, (int)nread);
                    args.ProcessedSoFar += (ulong)nread;
                    OnExtract(args);
                }
            } finally {
                ArrayPool <byte> .Shared.Return(buf);
            }
        }
예제 #6
0
        /// <summary>
        /// Extract this entry in directory specified by <paramref name="destinationDir"/>, optionally changing the entry's name to the
        /// one given in <paramref name="destinationFileName"/>. The destination file is opened using mode specified in the
        /// <paramref name="outputFileMode"/> parameter.
        /// </summary>
        /// <param name="destinationDir">Destination dir.</param>
        /// <param name="destinationFileName">Destination file name.</param>
        /// <param name="outputFileMode">Output file mode.</param>
        /// <param name="useNativeFileName">Make sure that the file name is converted to the operating system
        /// native format before extracting</param>
        /// <param name="password">Password of the ZipEntry</param>
        public string Extract(string destinationDir = null, string destinationFileName = null, FileMode outputFileMode = FileMode.Create, bool useNativeFileName = false, string password = null)
        {
            destinationDir = destinationDir?.Trim();
            if (String.IsNullOrEmpty(destinationDir))
            {
                destinationDir = String.IsNullOrEmpty(archive.DefaultExtractionDir) ? "." : archive.DefaultExtractionDir;
            }
            destinationFileName = destinationFileName?.Trim();
            string name = useNativeFileName ? NativeFullName : FullName;
            string path = Path.Combine(destinationDir, String.IsNullOrEmpty(destinationFileName) ? name : destinationFileName);
            string dir  = Path.GetDirectoryName(path);

            Directory.CreateDirectory(dir);

            var args = new EntryExtractEventArgs {
                Entry          = this,
                ProcessedSoFar = 0
            };

            OnExtract(args);
            if (!IsDirectory)
            {
                // TODO: handle non-regular files
                OperationFlags flags = OperationFlags.None;
                IntPtr         file  = IntPtr.Zero;
                try {
                    file = OpenArchive(password, flags);
                    if (file == IntPtr.Zero)
                    {
                        throw archive.GetErrorException();
                    }
                    DoExtract(file, path, outputFileMode, args);
                    PlatformServices.Instance.SetFileProperties(this, path, true);
                } finally {
                    if (file != IntPtr.Zero)
                    {
                        Native.zip_fclose(file);
                    }
                }
            }
            OnExtract(args);

            return(path);
        }
예제 #7
0
 void DoExtract(IntPtr zipFile, string destinationPath, FileMode outputFileMode, EntryExtractEventArgs args)
 {
     using (FileStream fs = File.Open(destinationPath, outputFileMode)) {
         DoExtract(zipFile, fs, args);
     }
 }