From b050cafa5d3220123f3cfa2ff5465f3b871eb93c Mon Sep 17 00:00:00 2001 From: CAOShurong <170531907+CAOShurong@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:34:27 +0800 Subject: [PATCH 1/2] Rewind Hadoop and raw streams after format detection --- .github/workflows/pypy.yml | 2 +- .github/workflows/wheel.yml | 4 ++-- src/snappy/snappy_formats.py | 3 +++ test_formats.py | 44 ++++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pypy.yml b/.github/workflows/pypy.yml index a9c0c48..6e50049 100644 --- a/.github/workflows/pypy.yml +++ b/.github/workflows/pypy.yml @@ -33,4 +33,4 @@ jobs: run: python setup.py develop - name: Pytest - run: pytest --verbose test_snappy.py + run: pytest --verbose test_snappy.py test_formats.py diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index 2cf7eff..1a4d700 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -38,7 +38,7 @@ jobs: run: pip install dist/python_snappy*.tar.gz - name: Pytest - run: pytest --verbose test_snappy.py + run: pytest --verbose test_snappy.py test_formats.py - name: Archive sdist uses: actions/upload-artifact@v4 @@ -70,7 +70,7 @@ jobs: name: Python ${{ matrix.os }} env: CIBW_TEST_REQUIRES: pytest - CIBW_TEST_COMMAND: "python -m pytest --verbose {project}/test_snappy.py" + CIBW_TEST_COMMAND: "python -m pytest --verbose {project}/test_snappy.py {project}/test_formats.py" CIBW_BEFORE_ALL_LINUX: yum install -y snappy-devel MACOSX_DEPLOYMENT_TARGET: "10.9" CIBW_REPAIR_WHEEL_COMMAND_WINDOWS: "delvewheel repair -w {dest_dir} {wheel}" diff --git a/src/snappy/snappy_formats.py b/src/snappy/snappy_formats.py index e230e0b..4cc6660 100644 --- a/src/snappy/snappy_formats.py +++ b/src/snappy/snappy_formats.py @@ -104,6 +104,9 @@ def guess_format_by_header(fin): def get_decompress_function(specified_format, fin): if specified_format == "auto": format, decompress_func = guess_format_by_header(fin) + if format in ("hadoop", "raw"): + # These probes seek to EOF; the decoder needs the complete stream. + fin.seek(0) return decompress_func return _DECOMPRESS_METHODS[specified_format] diff --git a/test_formats.py b/test_formats.py index 3e65a38..d7362a2 100644 --- a/test_formats.py +++ b/test_formats.py @@ -73,6 +73,50 @@ class TestFormatRawAuto(TestFormatBase): decompress_format = "auto" success = True +class TestAutoDecompress(TestCase): + data = bytes(range(256)) + + def compressed(self, name): + stream = io.BytesIO() + formats.get_compress_function(name)(io.BytesIO(self.data), stream) + stream.seek(0) + return stream + + def test_seekable_formats(self): + for name in ("hadoop", "raw"): + with self.subTest(format=name): + compressed = self.compressed(name) + decompress = formats.get_decompress_function("auto", compressed) + output = io.BytesIO() + decompress(compressed, output) + self.assertEqual(output.getvalue(), self.data) + + def test_cli_seekable_formats(self): + with tempfile.TemporaryDirectory() as tmpdir: + source = os.path.join(tmpdir, "input.snappy") + target = os.path.join(tmpdir, "output.bin") + for name in ("hadoop", "raw"): + with self.subTest(format=name): + with open(source, "wb") as stream: + stream.write(self.compressed(name).getvalue()) + result = subprocess.run( + [sys.executable, "-m", "snappy", "-d", source, target], + capture_output=True, + ) + self.assertEqual(result.returncode, 0, result.stderr) + with open(target, "rb") as stream: + self.assertEqual(stream.read(), self.data) + + def test_cli_framed_stdin(self): + result = subprocess.run( + [sys.executable, "-m", "snappy", "-d"], + input=self.compressed("framing").getvalue(), + capture_output=True, + ) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout, self.data) + + class TestDecompressFunction(TestCase): def test_auto_returns_function(self): data = b"hello world" From a54df27b417fd01507e0992aa7c78c1ec3ba1166 Mon Sep 17 00:00:00 2001 From: CAOShurong <170531907+CAOShurong@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:25:52 +0800 Subject: [PATCH 2/2] Use a supported macOS Intel runner --- .github/workflows/wheel.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index 1a4d700..2e33228 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -51,7 +51,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-22.04, macos-14, windows-2022] + os: [ubuntu-22.04, macos-15-intel, windows-2022] architecture: ["x64"] linux_archs: ["auto s390x"] include: