tangled
alpha
login
or
join now
microcosm.blue
/
repo-stream
14
fork
atom
Fast and robust atproto CAR file processing in rust
14
fork
atom
overview
issues
pulls
1
pipelines
clean up builder
bad-example.com
2 months ago
a84cea74
68d24fa1
+18
-41
1 changed file
expand all
collapse all
unified
split
src
drive.rs
+18
-41
src/drive.rs
···
115
115
Disk(NeedDisk<R>),
116
116
}
117
117
118
118
+
/// Processor that just returns the raw blocks
119
119
+
#[inline]
120
120
+
pub fn noop(block: Bytes) -> Bytes {
121
121
+
block
122
122
+
}
123
123
+
118
124
/// Builder-style driver setup
119
125
#[derive(Debug, Clone)]
120
126
pub struct DriverBuilder {
121
127
pub mem_limit_mb: usize,
128
128
+
pub block_processor: fn(Bytes) -> Bytes,
122
129
}
123
130
124
131
impl Default for DriverBuilder {
125
132
fn default() -> Self {
126
126
-
Self { mem_limit_mb: 16 }
133
133
+
Self {
134
134
+
mem_limit_mb: 16,
135
135
+
block_processor: noop,
136
136
+
}
127
137
}
128
138
}
129
139
130
130
-
/// Processor that just returns the raw blocks
131
131
-
#[inline]
132
132
-
pub fn noop(block: Bytes) -> Bytes {
133
133
-
block
134
134
-
}
135
135
-
136
140
impl DriverBuilder {
137
141
/// Begin configuring the driver with defaults
138
142
pub fn new() -> Self {
···
141
145
/// Set the in-memory size limit, in MiB
142
146
///
143
147
/// Default: 16 MiB
144
144
-
pub fn with_mem_limit_mb(self, new_limit: usize) -> Self {
145
145
-
Self {
146
146
-
mem_limit_mb: new_limit,
147
147
-
}
148
148
+
pub fn with_mem_limit_mb(mut self, new_limit: usize) -> Self {
149
149
+
self.mem_limit_mb = new_limit;
150
150
+
self
148
151
}
152
152
+
149
153
/// Set the block processor
150
154
///
151
155
/// Default: noop, raw blocks will be emitted
152
152
-
pub fn with_block_processor(
153
153
-
self,
154
154
-
block_processor: fn(Bytes) -> Bytes,
155
155
-
) -> DriverBuilderWithProcessor {
156
156
-
DriverBuilderWithProcessor {
157
157
-
mem_limit_mb: self.mem_limit_mb,
158
158
-
block_processor,
159
159
-
}
156
156
+
pub fn with_block_processor(mut self, new_processor: fn(Bytes) -> Bytes) -> DriverBuilder {
157
157
+
self.block_processor = new_processor;
158
158
+
self
160
159
}
161
161
-
/// Begin processing an atproto MST from a CAR file
162
162
-
pub async fn load_car<R: AsyncRead + Unpin>(&self, reader: R) -> Result<Driver<R>, DriveError> {
163
163
-
Driver::load_car(reader, noop, self.mem_limit_mb).await
164
164
-
}
165
165
-
}
166
160
167
167
-
/// Builder-style driver intermediate step
168
168
-
///
169
169
-
/// start from `DriverBuilder`
170
170
-
#[derive(Debug, Clone)]
171
171
-
pub struct DriverBuilderWithProcessor {
172
172
-
pub mem_limit_mb: usize,
173
173
-
pub block_processor: fn(Bytes) -> Bytes,
174
174
-
}
175
175
-
176
176
-
impl DriverBuilderWithProcessor {
177
177
-
/// Set the in-memory size limit, in MiB
178
178
-
///
179
179
-
/// Default: 16 MiB
180
180
-
pub fn with_mem_limit_mb(mut self, new_limit: usize) -> Self {
181
181
-
self.mem_limit_mb = new_limit;
182
182
-
self
183
183
-
}
184
161
/// Begin processing an atproto MST from a CAR file
185
162
pub async fn load_car<R: AsyncRead + Unpin>(&self, reader: R) -> Result<Driver<R>, DriveError> {
186
163
Driver::load_car(reader, self.block_processor, self.mem_limit_mb).await