neaten up newlines
This commit is contained in:
parent
6831bd52bb
commit
73f01d3e81
|
@ -3,6 +3,7 @@ def pad_up(size, factor):
|
||||||
x = size + factor - 1
|
x = size + factor - 1
|
||||||
return x - (x % factor)
|
return x - (x % factor)
|
||||||
|
|
||||||
|
|
||||||
def bits(ntotal, nset):
|
def bits(ntotal, nset):
|
||||||
"""Return a buffer of ntotal bits with the first nset set to 1"""
|
"""Return a buffer of ntotal bits with the first nset set to 1"""
|
||||||
assert ntotal % 8 == 0
|
assert ntotal % 8 == 0
|
||||||
|
@ -25,6 +26,7 @@ def bits(ntotal, nset):
|
||||||
|
|
||||||
return bytes(accum)
|
return bytes(accum)
|
||||||
|
|
||||||
|
|
||||||
def chunkify(b, blksize):
|
def chunkify(b, blksize):
|
||||||
for i in range(0, len(b), blksize):
|
for i in range(0, len(b), blksize):
|
||||||
ab = b[i:i+blksize]
|
ab = b[i:i+blksize]
|
||||||
|
|
|
@ -51,6 +51,7 @@ def unpack_extent_record(record):
|
||||||
if f: l.append((e, f))
|
if f: l.append((e, f))
|
||||||
return l
|
return l
|
||||||
|
|
||||||
|
|
||||||
def _unpack_btree_node(buf, start):
|
def _unpack_btree_node(buf, start):
|
||||||
"""Slice a btree node into records, including the 14-byte node descriptor"""
|
"""Slice a btree node into records, including the 14-byte node descriptor"""
|
||||||
ndFLink, ndBLink, ndType, ndNHeight, ndNRecs = struct.unpack_from('>LLBBH', buf, start)
|
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)]
|
records = [bytes(buf[start+i_start:start+i_stop]) for (i_start, i_stop) in zip(starts, stops)]
|
||||||
return ndFLink, ndBLink, ndType, ndNHeight, records
|
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):
|
def dump_btree(buf):
|
||||||
"""Walk an HFS B*-tree, returning an iterator of (key, value) tuples."""
|
"""Walk an HFS B*-tree, returning an iterator of (key, value) tuples."""
|
||||||
|
|
||||||
|
@ -82,21 +102,6 @@ def dump_btree(buf):
|
||||||
break
|
break
|
||||||
this_leaf = ndFLink
|
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):
|
def make_btree(records, bthKeyLen):
|
||||||
nodelist = [] # append to this as we go
|
nodelist = [] # append to this as we go
|
||||||
|
|
|
@ -4,7 +4,6 @@ import collections
|
||||||
_CASE = list(range(256)) # cheating, fix this!
|
_CASE = list(range(256)) # cheating, fix this!
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def _to_lower(orig):
|
def _to_lower(orig):
|
||||||
return bytes(_CASE[x] for x in orig)
|
return bytes(_CASE[x] for x in orig)
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ def _catalog_rec_sort(b):
|
||||||
|
|
||||||
return b[:4] + bytes(order[ch] for ch in b[5:])
|
return b[:4] + bytes(order[ch] for ch in b[5:])
|
||||||
|
|
||||||
|
|
||||||
def _suggest_allocblk_size(volsize, minalign):
|
def _suggest_allocblk_size(volsize, minalign):
|
||||||
min_nonalloc_blks = 6 # just for this estimation
|
min_nonalloc_blks = 6 # just for this estimation
|
||||||
retval = minalign
|
retval = minalign
|
||||||
|
|
Loading…
Reference in New Issue