Repository: milesgranger/cramjam (language: python)

Issue:
Equality check on values for Buffer
This should work: https://github.com/andrix/python-snappy/pull/130#issuecomment-1927383098


Discussion / hints:

Fix patch:
diff --git a/Cargo.lock b/Cargo.lock
index d75deed4..f86bf36b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -295,14 +295,14 @@ version = "0.1.1"
 dependencies = [
  "bytesize",
  "clap 4.2.7",
- "libcramjam",
+ "libcramjam 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "cramjam-python"
 version = "2.8.1"
 dependencies = [
- "libcramjam",
+ "libcramjam 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "pyo3",
 ]
 
@@ -526,6 +526,24 @@ dependencies = [
  "zstd",
 ]
 
+[[package]]
+name = "libcramjam"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1122d475df7c0461d2ed3af60e609512e4ec0c1c98156be1f320513b84fd9510"
+dependencies = [
+ "brotli",
+ "bzip2",
+ "cbindgen",
+ "flate2",
+ "libdeflater",
+ "lz4",
+ "snap",
+ "xz2",
+ "zstd",
+ "zstd-safe",
+]
+
 [[package]]
 name = "libdeflate-sys"
 version = "1.19.0"
diff --git a/cramjam-python/src/io.rs b/cramjam-python/src/io.rs
index 32f35126..d9561204 100644
--- a/cramjam-python/src/io.rs
+++ b/cramjam-python/src/io.rs
@@ -432,6 +432,9 @@ impl RustyBuffer {
     fn __repr__(&self) -> String {
         format!("cramjam.Buffer<len={:?}>", self.len())
     }
+    fn __eq__(&self, other: &Self) -> bool {
+        self.inner == other.inner
+    }
     fn __bool__(&self) -> bool {
         self.len() > 0
     }


Test patch:
diff --git a/cramjam-python/tests/test_variants.py b/cramjam-python/tests/test_variants.py
index a24e81c1..ecc9181b 100644
--- a/cramjam-python/tests/test_variants.py
+++ b/cramjam-python/tests/test_variants.py
@@ -360,3 +360,9 @@ def test_variants_stream_decompressors(variant_str):
     # Calling .finish renders decompressor unusable after. (API consistency with other libs)
     with pytest.raises(cramjam.DecompressionError):
         decompressor.finish()
+
+
+def test_buffer_cmp():
+    assert cramjam.Buffer() == cramjam.Buffer()
+    assert cramjam.Buffer(b"some bytes") == cramjam.Buffer(b"some bytes")
+    assert cramjam.Buffer(b"some bytes") != cramjam.Buffer(b"other bytes")