示例#1
0
        public void DoubleClose()
        {
            var memStream = new TrackedMemoryStream();
            var s         = new GZipOutputStream(memStream);

            s.Finish();
#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif
#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif

            memStream = new TrackedMemoryStream();
            using (GZipOutputStream no2 = new GZipOutputStream(memStream)) {
#if NET451
                s.Close();
#elif NETCOREAPP1_0
                s.Dispose();
#endif
            }
        }
示例#2
0
        public void OutputStreamOwnership()
        {
            var memStream = new TrackedMemoryStream();
            var s         = new GZipOutputStream(memStream);

            Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
            Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");

#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif

            Assert.IsTrue(memStream.IsClosed, "Should be closed after parent owner close");
            Assert.IsTrue(memStream.IsDisposed, "Should be disposed after parent owner close");

            memStream = new TrackedMemoryStream();
            s         = new GZipOutputStream(memStream);

            Assert.IsFalse(memStream.IsClosed, "Shouldnt be closed initially");
            Assert.IsFalse(memStream.IsDisposed, "Shouldnt be disposed initially");

            s.IsStreamOwner = false;
#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif

            Assert.IsFalse(memStream.IsClosed, "Should not be closed after parent owner close");
            Assert.IsFalse(memStream.IsDisposed, "Should not be disposed after parent owner close");
        }
示例#3
0
    public static byte[] Compress(byte[] bytesToCompress)
    {
        byte[]       rebyte = null;
        MemoryStream ms     = new MemoryStream();

        GZipOutputStream s = new GZipOutputStream(ms);

        try
        {
            s.Write(bytesToCompress, 0, bytesToCompress.Length);
            s.Flush();
            s.Finish();
        }
        catch (System.Exception ex)
        {
#if UNITY_EDITOR
            Debug.Log(ex);
#endif
        }

        ms.Seek(0, SeekOrigin.Begin);

        rebyte = ms.ToArray();

        s.Close();
        ms.Close();

        s.Dispose();
        ms.Dispose();

        return(rebyte);
    }
示例#4
0
        public byte[] Encompress(byte[] data)
        {
            byte[]           result;
            MemoryStream     ms     = new MemoryStream();
            GZipOutputStream stream = new GZipOutputStream(ms);

            stream.Write(data, 0, data.Length);
            stream.Close();
            stream.Dispose();
            result = ms.ToArray();
            ms.Close();
            ms.Dispose();
            return(result);
        }
示例#5
0
        public void DoubleFooter()
        {
            var memStream = new TrackedMemoryStream();
            var s         = new GZipOutputStream(memStream);

            s.Finish();
            Int64 length = memStream.Length;

#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif
            Assert.AreEqual(length, memStream.ToArray().Length);
        }
示例#6
0
        public void WriteAfterClose()
        {
            var memStream = new TrackedMemoryStream();
            var s         = new GZipOutputStream(memStream);

#if NET451
            s.Close();
#elif NETCOREAPP1_0
            s.Dispose();
#endif

            try
            {
                s.WriteByte(7);
                Assert.Fail("Write should fail");
            } catch {
            }
        }
示例#7
0
        /// <summary>
        /// Compress the specified sBuffer.
        /// </summary>
        /// <param name="sBuffer">S buffer.</param>
        public static string Compress(string sBuffer)
        {
            string b64 = null;

            MemoryStream     rawDataStream = null;
            GZipOutputStream gzipOut       = null;

            try {
                rawDataStream = new MemoryStream();
                gzipOut       = new GZipOutputStream(rawDataStream);

                byte[] sIn = UTF8Encoding.UTF8.GetBytes(sBuffer);
                gzipOut.IsStreamOwner = false;

                gzipOut.Write(sIn, 0, sIn.Length);
                gzipOut.Close();

                byte[] compressed = rawDataStream.ToArray();
                // data sent to the php service
                b64 = Convert.ToBase64String(compressed);
            } catch (Exception ex) {
                ConsoleEx.DebugLog("GZip compress error : " + ex.ToString());
            } finally {
                if (gzipOut != null)
                {
                    gzipOut.Dispose();
                    gzipOut = null;
                }

                if (rawDataStream != null)
                {
                    rawDataStream.Dispose();
                    rawDataStream = null;
                }
            }

            return(b64);
        }
 /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
 public void Dispose()
 {
     gzip?.Dispose();
     gzoStream?.Dispose();
 }