Skip to content

Conversation

@darvid
Copy link
Owner

@darvid darvid commented Dec 6, 2025

Summary

  • Update Database_scan to accept any buffer protocol object (memoryview, bytearray, etc.) instead of requiring exact bytes objects
  • Update Stream_scan to use y* format specifier for buffer protocol support
  • Add tests for memoryview and bytearray scanning in block, stream, and chimera modes

This allows users to scan data without copying when they already have it in a buffer:

db.scan(memoryview(b"foobar"), match_event_handler=callback)
db.scan(bytearray(b"foobar"), match_event_handler=callback)

with db.stream(match_event_handler=callback) as stream:
    stream.scan(memoryview(b"foo"))

Closes #250

Test plan

  • test_chimera_scan_memoryview - chimera mode with memoryview
  • test_block_scan_memoryview - block mode with memoryview
  • test_block_scan_bytearray - block mode with bytearray
  • test_stream_scan_memoryview - stream mode with memoryview
  • test_stream_scan_bytearray - stream mode with bytearray
  • All existing tests still pass (32/32)

- Update Database_scan to accept any buffer protocol object (memoryview,
  bytearray, etc.) instead of requiring exact bytes objects
- Update Stream_scan to use y* format specifier for buffer protocol support
- Add tests for memoryview and bytearray scanning in block, stream, and
  chimera modes

Closes #250
@darvid darvid merged commit 3077019 into main Dec 6, 2025
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support buffer protocol in block/stream mode

2 participants