-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rebuild index from data file. Some fixes to existing tools and made writing a little less error prone.
- Loading branch information
Showing
6 changed files
with
160 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from pimlico.utils.varint import decode_stream, encode | ||
|
||
|
||
def _read_var_length_data(reader): | ||
""" | ||
Read some data from a file-like object by first reading a varint that says how many | ||
bytes are in the data and then reading the data immediately following. | ||
""" | ||
# Get a single varint from the reader stream | ||
data_length = decode_stream(reader) | ||
# Read the data as a bytes array | ||
return reader.read(data_length) | ||
|
||
|
||
def _skip_var_length_data(reader): | ||
""" | ||
Like read_var_length_data, but doesn't actually read the data. Just reads the length | ||
indicator and seeks to the end of the data. | ||
""" | ||
data_length = decode_stream(reader) | ||
reader.seek(data_length, 1) | ||
|
||
|
||
def _write_var_length_data(writer, data): | ||
""" | ||
Write some data to a file-like object by first writing a varint that says how many | ||
bytes are in the data and then writing the data immediately following. | ||
""" | ||
# Store the length of the data in bytes | ||
data_length = len(data) | ||
writer.write(encode(data_length)) | ||
# Write the data as a bytes array | ||
return writer.write(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters