コード例 #1
0
        static void NextCompress(IAsyncResult result = null)
        {
            if (m_ZipFiles == null || m_ZipFiles.Length <= 0 || m_ZipOutStream == null || m_outStream == null || m_ZipCompressIdx < 0)
            {
                return;
            }

            if (result != null)
            {
                m_ZipOutStream.EndWrite(result);
                m_ZipOutStream.Flush();
            }

            if (m_ZipCompressIdx >= m_ZipFiles.Length)
            {
                ResetCompress();
                return;
            }

            string fileName = m_ZipFiles[m_ZipCompressIdx];

            if (string.IsNullOrEmpty(fileName))
            {
                ++m_ZipCompressIdx;
                NextCompress();
                return;
            }

            FileStream inStream = new FileStream(fileName, FileMode.Open);

            string   name     = Path.GetFileName(fileName);
            ZipEntry zipEntry = new ZipEntry(name);

            m_ZipOutStream.PutNextEntry(zipEntry);

            while (true)
            {
                int read = inStream.Read(m_Buf, 0, m_Buf.Length);

                if (read > 0)
                {
                    m_ZipOutStream.Write(m_Buf, 0, read);
                    m_ZipOutStream.Flush();
                    m_outStream.Flush();
                }
                else
                {
                    inStream.Close();
                    inStream.Dispose();
                    break;
                }
            }

            DoCopressed();
        }