1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//! Fast reader for Bitcoin Core `blk*.dat` files.
//!
//! Reads raw block data directly from Bitcoin Core's block storage, using the
//! LevelDB index to locate blocks by height. Automatically detects and decodes
//! the XOR encoding introduced in Bitcoin Core 28.0.
//!
//! # Quick start
//!
//! ```no_run
//! use blk_reader::{BlockIterator, BlkReaderConfig};
//! use std::path::PathBuf;
//!
//! let config = BlkReaderConfig {
//! blocks_dir: PathBuf::from("/home/user/.bitcoin/blocks"),
//! index_dir: PathBuf::from("/home/user/.bitcoin/blocks/index"),
//! start_height: 0,
//! end_height: 100,
//! ..Default::default()
//! };
//!
//! for result in BlockIterator::new(config).unwrap() {
//! let block = result.unwrap();
//! println!("height={} size={} bytes", block.height, block.data.len());
//! }
//! ```
//!
//! # XOR decoding
//!
//! Bitcoin Core 28.0 introduced XOR encoding of `blk*.dat` files to prevent
//! false-positive virus scanner alerts. The key is stored in `blocks/xor.dat`.
//! This crate detects the file automatically — no configuration needed.
//!
//! # Reading a single block
//!
//! If you already know the file index and byte offset (e.g. from your own
//! LevelDB query), use [`BlkReader`] directly:
//!
//! ```no_run
//! use blk_reader::BlkReader;
//! use std::path::PathBuf;
//!
//! let mut reader = BlkReader::new(
//! PathBuf::from("/home/user/.bitcoin/blocks"),
//! 8 * 1024 * 1024, // read buffer
//! );
//! // Genesis block: file 0, data offset 8
//! let raw = reader.read_block_at(0, 8).unwrap();
//! assert_eq!(raw.len(), 285);
//! ```
pub use BlkReaderError;
pub use ;
pub use BlkReader;
pub use ;