Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parity-bitcoin
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
parity
parity-bitcoin
Commits
cd4e99bc
Commit
cd4e99bc
authored
5 years ago
by
Svyatoslav Nikolsky
Browse files
Options
Downloads
Patches
Plain Diff
ignore zero-filled gaps in blk files
parent
faebbc38
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
import/src/block.rs
+13
-7
13 additions, 7 deletions
import/src/block.rs
serialization/src/reader.rs
+18
-0
18 additions, 0 deletions
serialization/src/reader.rs
with
31 additions
and
7 deletions
import/src/block.rs
+
13
−
7
View file @
cd4e99bc
...
...
@@ -12,12 +12,18 @@ pub struct Block {
impl
Deserializable
for
Block
{
fn
deserialize
<
T
>
(
reader
:
&
mut
Reader
<
T
>
)
->
Result
<
Self
,
ReaderError
>
where
T
:
io
::
Read
{
let
block
=
Block
{
magic
:
try
!
(
reader
.read
()),
block_size
:
try
!
(
reader
.read
()),
block
:
try
!
(
reader
.read
()),
};
// We never knew how to parse blocks index file => we were assuming that blocks are stored
// in the *.blk files next to each other, without any gaps.
// It seems that this isn't true && there are (sometimes) zero-filled (always???) gaps between
// adjacent blocks.
// The straightforward soultion is to skip zero bytes. This will work because magic is designed
// not to have zero bytes in it AND block is always prefixed with magic.
reader
.skip_while
(
&
|
byte
|
byte
==
0
)
?
;
Ok
(
block
)
Ok
(
Block
{
magic
:
reader
.read
()
?
,
block_size
:
reader
.read
()
?
,
block
:
reader
.read
()
?
,
})
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
serialization/src/reader.rs
+
18
−
0
View file @
cd4e99bc
...
...
@@ -89,6 +89,24 @@ impl<R> Reader<R> where R: io::Read {
T
::
deserialize
(
&
mut
reader
)
}
pub
fn
skip_while
(
&
mut
self
,
predicate
:
&
Fn
(
u8
)
->
bool
)
->
Result
<
(),
Error
>
{
let
mut
next_buffer
=
[
0u8
];
loop
{
let
next
=
match
self
.peeked
.take
()
{
Some
(
peeked
)
=>
peeked
,
None
=>
match
self
.buffer
.read
(
&
mut
next_buffer
)
?
{
0
=>
return
Ok
(()),
_
=>
next_buffer
[
0
],
},
};
if
!
predicate
(
next
)
{
self
.peeked
=
Some
(
next
);
return
Ok
(());
}
}
}
pub
fn
read_slice
(
&
mut
self
,
bytes
:
&
mut
[
u8
])
->
Result
<
(),
Error
>
{
io
::
Read
::
read_exact
(
self
,
bytes
)
.map_err
(|
_
|
Error
::
UnexpectedEnd
)
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment