Commits

Jeff Hardy  committed ba92874

Fix decompressobj.unused_data and .unconsumed_tail

  • Participants
  • Parent commits b602eca

Comments (0)

Files changed (6)

+syntax: glob
+*\bin
+*\obj
+*.user
+*.suo

File IronPython.Zlib/Decompress.cs

 
             if(max_length > 0)
             {
-                _unconsumed_tail = ZlibModule.Latin1.GetString(zst.next_in, 0, zst.avail_in);
+                _unconsumed_tail = ZlibModule.Latin1.GetString(zst.next_in, zst.next_in_index, zst.avail_in);
             }
 
             if(err == Z_STREAM_END)
             {
-                _unused_data += ZlibModule.Latin1.GetString(zst.next_in, 0, zst.avail_in);
+                _unused_data += ZlibModule.Latin1.GetString(zst.next_in, zst.next_in_index, zst.avail_in);
             }
             else if(err != Z_OK && err != Z_BUF_ERROR)
             {

File IronPython.Zlib/IronPython.Zlib.csproj

   <ItemGroup>
     <Reference Include="IronPython, Version=2.6.0.1, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\Bin\IronPython-48484\IronPython.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\IronPython.dll</HintPath>
+    </Reference>
+    <Reference Include="IronPython.Modules, Version=2.6.0.1, Culture=neutral, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\IronPython.Modules.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.Scripting, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\Bin\IronPython-48484\Microsoft.Scripting.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\Microsoft.Scripting.dll</HintPath>
     </Reference>
     <Reference Include="Microsoft.Scripting.Core, Version=0.9.5.1, Culture=neutral, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
-      <HintPath>..\..\..\Bin\IronPython-48484\Microsoft.Scripting.Core.dll</HintPath>
+      <HintPath>..\..\..\..\..\Bin\IronPython-Nightly\latest.debug\Microsoft.Scripting.Core.dll</HintPath>
     </Reference>
     <Reference Include="System" />
     <Reference Include="System.Data" />
   <Target Name="AfterBuild">
   </Target>
   -->
+  <PropertyGroup>
+    <PostBuildEvent>copy /Y "$(TargetPath)" "C:\Users\Jeff\Bin\IronPython-2.6B1\DLLs"</PostBuildEvent>
+  </PropertyGroup>
 </Project>

File IronPython.Zlib/IronPython.Zlib.suo

Binary file removed.

File IronPython.Zlib/ZlibModule.cs

 
         #region compress
 
+        public static string compress(PythonBuffer data)
+        {
+            return compress(data, Z_DEFAULT_COMPRESSION);
+        }
+
+        public static string compress(PythonBuffer data, int level)
+        {
+            return compress(data.ToString(), level);
+        }
+
         public static string compress(string data)
         {
             return compress(data, Z_DEFAULT_COMPRESSION);

File IronPython.Zlib/run_tests.py

 #clr.AddReferenceToFileAndPath(r'C:\Users\Jeff\Documents\Repositories\code\IronPython.Zlib\bin\Debug\IronPython.Zlib.dll')
 
 import zlib
-import gzip
-import tarfile
 
-f = tarfile.open(r'C:\Users\Jeff\Documents\Repositories\simplejson-2.0.6.tar.gz')
+#def test_crc32_basic():
+#   calculated_crc32 = zlib.crc32("\xFF") & 0xFFFFFFFF
+#   correct_crc32 = 0xFF000000
+#   if calculated_crc32 != correct_crc32:
+#       raise AssertionError("CRC32 value incorrect %08X" % (calculated_crc32,))
+
+#def test_resume_negative_crc32():
+#   previous_crc32 = -1
+#   calculated_crc32 = zlib.crc32("", previous_crc32)
+#   if calculated_crc32 != previous_crc32:
+#       raise AssertionError("CRC32 should not change if empty string is added %08X" % (calculated_crc32,))
+
+def test_decompressobj_unused_data():
+   s = "\x03\x00leftover" # minimal two byte stream plus eight bytes trailer
+   dco = zlib.decompressobj(-zlib.MAX_WBITS)
+   dco.decompress(s)
+   if dco.unused_data != s[2:]:
+       raise AssertionError("Instead of last eight bytes, got %r" % (dco.unused_data,))
+
+test_decompressobj_unused_data()
+
+# import gzip
+# import tarfile
+
+#f = tarfile.open(r'C:\Users\Jeff\Documents\Repositories\simplejson-2.0.6.tar.gz')
 
 #from test import test_zlib
 #test_zlib.test_main()