neaten up newlines

This commit is contained in:
Elliot Nunn 2018-10-08 08:20:03 +08:00
parent 6831bd52bb
commit 73f01d3e81
4 changed files with 23 additions and 16 deletions

View File

@ -3,6 +3,7 @@ def pad_up(size, factor):
x = size + factor - 1
return x - (x % factor)
def bits(ntotal, nset):
"""Return a buffer of ntotal bits with the first nset set to 1"""
assert ntotal % 8 == 0
@ -25,6 +26,7 @@ def bits(ntotal, nset):
return bytes(accum)
def chunkify(b, blksize):
for i in range(0, len(b), blksize):
ab = b[i:i+blksize]

View File

@ -51,6 +51,7 @@ def unpack_extent_record(record):
if f: l.append((e, f))
return l
def _unpack_btree_node(buf, start):
"""Slice a btree node into records, including the 14-byte node descriptor"""
ndFLink, ndBLink, ndType, ndNHeight, ndNRecs = struct.unpack_from('>LLBBH', buf, start)
@ -60,6 +61,25 @@ def _unpack_btree_node(buf, start):
records = [bytes(buf[start+i_start:start+i_stop]) for (i_start, i_stop) in zip(starts, stops)]
return ndFLink, ndBLink, ndType, ndNHeight, records
def _pack_leaf_record(key, value):
"""Pack a key-value pair to go into a leaf node as a record"""
if len(value) & 1: value += b'\x00'
b = bytes([len(key)+1, 0, *key])
if len(b) & 1: b += bytes(1)
b += value
return b
def _make_index_record(rec, pointer):
"""Convert a key-value to a special key-pointer record"""
rec = rec[:1+rec[0]]
rec = b'\x25' + rec[1:]
rec += bytes(rec[0]+1-len(rec))
rec += struct.pack('>L', pointer)
return rec
def dump_btree(buf):
"""Walk an HFS B*-tree, returning an iterator of (key, value) tuples."""
@ -82,21 +102,6 @@ def dump_btree(buf):
break
this_leaf = ndFLink
def _pack_leaf_record(key, value):
"""Pack a key-value pair to go into a leaf node as a record"""
if len(value) & 1: value += b'\x00'
b = bytes([len(key)+1, 0, *key])
if len(b) & 1: b += bytes(1)
b += value
return b
def _make_index_record(rec, pointer):
"""Convert a key-value to a special key-pointer record"""
rec = rec[:1+rec[0]]
rec = b'\x25' + rec[1:]
rec += bytes(rec[0]+1-len(rec))
rec += struct.pack('>L', pointer)
return rec
def make_btree(records, bthKeyLen):
nodelist = [] # append to this as we go

View File

@ -4,7 +4,6 @@ import collections
_CASE = list(range(256)) # cheating, fix this!
def _to_lower(orig):
return bytes(_CASE[x] for x in orig)

View File

@ -50,6 +50,7 @@ def _catalog_rec_sort(b):
return b[:4] + bytes(order[ch] for ch in b[5:])
def _suggest_allocblk_size(volsize, minalign):
min_nonalloc_blks = 6 # just for this estimation
retval = minalign