Jeff Hardy avatar Jeff Hardy committed fde5d2f

Use the [BytesConversion] attribute to reduce the number of overloads.

Comments (0)

Files changed (3)

  * *************************************************************************/
 
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Runtime.InteropServices;
 using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime;
 After calling this function, some of the input data may still
 be stored in internal buffers for later processing.
 Call the flush() method to clear these buffers.")]
-        public string compress(string data)
+        public string compress([BytesConversion]IList<byte> data)
         {
-            byte[] input = ZlibModule.Latin1.GetBytes(data);
+            byte[] input = data.ToArray();
             byte[] output = new byte[ZlibModule.DEFAULTALLOC];
 
             long start_total_out = zst.total_out;

src/Decompress.cs

  * *************************************************************************/
 
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Runtime.InteropServices;
 using ComponentAce.Compression.Libs.ZLib;
 using IronPython.Runtime;
             get { return _unconsumed_tail; }
         }
 
-        public string decompress(string value)
-        {
-            return decompress(value, 0);
-        }
-
         [Documentation(@"decompress(data, max_length) -- Return a string containing the decompressed
 version of the data.
 
 If the max_length parameter is specified then the return value will be
 no longer than max_length.  Unconsumed input data will be stored in
 the unconsumed_tail attribute.")]
-        public string decompress(string value, int max_length)
+        public string decompress([BytesConversion]IList<byte> value, [DefaultParameterValue(0)]int max_length)
         {
             if(max_length < 0) throw new ArgumentException("max_length must be greater than zero");
 
-            byte[] input = ZlibModule.Latin1.GetBytes(value);
+            byte[] input = value.ToArray();
             byte[] output = new byte[max_length > 0 ? max_length : ZlibModule.DEFAULTALLOC];
 
             long start_total_out = zst.total_out;

src/ZlibModule.cs

  * *************************************************************************/
 
 using System;
+using System.Collections.Generic;
+using System.Linq;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
 using ComponentAce.Compression.Libs.ZLib;
 
 An optional starting value can be specified.  The returned checksum is
 a signed integer.")]
-        public static int adler32(string data, [DefaultParameterValue(1L)] long baseValue)
+        public static int adler32([BytesConversion]IList<byte> data, [DefaultParameterValue(1L)] long baseValue)
         {
-            return adler32(Latin1.GetBytes(data), baseValue);
-        }
-
-        public static int adler32(byte[] data, [DefaultParameterValue(1L)] long baseValue)
-        {
-            return (int)Adler32.GetAdler32Checksum(baseValue, data, 0, data.Length);
+            return (int)Adler32.GetAdler32Checksum(baseValue, data.ToArray(), 0, data.Count());
         }
 
         [Documentation(@"crc32(string[, start]) -- Compute a CRC-32 checksum of string.
 
 An optional starting value can be specified.  The returned checksum is
 a signed integer.")]
-        public static int crc32(string data, [DefaultParameterValue(0L)] long baseValue)
+        public static int crc32([BytesConversion]IList<byte> data, [DefaultParameterValue(0L)] long baseValue)
         {
             if(baseValue < int.MinValue || baseValue > uint.MaxValue)
                 throw new ArgumentOutOfRangeException("baseValue");
 
             if(baseValue >= 0 && baseValue <= uint.MaxValue)
-                return IronPython.Modules.PythonBinaryAscii.crc32(data, (uint)baseValue);
+                return IronPython.Modules.PythonBinaryAscii.crc32(data.ToArray(), (uint)baseValue);
             else
-                return IronPython.Modules.PythonBinaryAscii.crc32(data, (int)baseValue);
-        }
-
-        public static int crc32(byte[] data, [DefaultParameterValue(0L)] long baseValue)
-        {
-            if(baseValue < int.MinValue || baseValue > uint.MaxValue)
-                throw new ArgumentOutOfRangeException("baseValue");
-
-            if(baseValue >= 0 && baseValue <= uint.MaxValue)
-                return IronPython.Modules.PythonBinaryAscii.crc32(data, (uint)baseValue);
-            else
-                return IronPython.Modules.PythonBinaryAscii.crc32(data, (int)baseValue);
-        }
-
-
-        public static string compress(PythonBuffer data, 
-            [DefaultParameterValue(Z_DEFAULT_COMPRESSION)]int level)
-        {
-            return compress(data.ToString(), level);
+                return IronPython.Modules.PythonBinaryAscii.crc32(data.ToArray(), (int)baseValue);
         }
 
         [Documentation(@"compress(string[, level]) -- Returned compressed string.
 
 Optional arg level is the compression level, in 1-9.")]
-        public static string compress(string data,
+        public static string compress([BytesConversion]IList<byte> data,
             [DefaultParameterValue(Z_DEFAULT_COMPRESSION)]int level)
         {
-            byte[] input = Latin1.GetBytes(data);
+            byte[] input = data.ToArray();
             byte[] output = new byte[input.Length + input.Length / 1000 + 12 + 1];
 
             ZStream zst = new ZStream();
 
 Optional arg wbits is the window buffer size.  Optional arg bufsize is
 the initial output buffer size.")]
-        public static string decompress(string data,
+        public static string decompress([BytesConversion]IList<byte> data,
             [DefaultParameterValue(MAX_WBITS)]int wbits,
             [DefaultParameterValue(DEFAULTALLOC)]int bufsize)
         {
-            byte[] input = Latin1.GetBytes(data);
+            byte[] input = data.ToArray();
 
             byte[] outputBuffer = new byte[bufsize];
             byte[] output = new byte[bufsize];
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.