Exemplo n.º 1
0
Arquivo: inx.py Projeto: rubyu/inx2csv
 def parse(self, path):
     buf = open(path, "rb").read()
     eof = len(buf)
     logging.debug("path: %s", path)
     logging.debug("parsing INX of %s(%s) bytes", eof, hex(eof))
     self._set_pos(0)
     
     num_entries = read_int(buf, self._pos, 1)
     logging.debug("number of entries: %s", num_entries)
     self._add_pos(1)
     
     result = INXParseResult(buf)
     for i in xrange(num_entries):
         logging.debug("entry %s of %s", i+1, num_entries)
         
         content_start = read_int(buf, self._pos, 8)
         logging.debug("content_start: %s (%s)", content_start, hex(content_start))
         self._add_pos(8)
         
         name_length = read_int(buf, self._pos, 1)
         logging.debug("name_length: %s", name_length)
         self._add_pos(1)
         
         name = read_str(buf, self._pos, name_length)
         logging.debug("name: %s", name)
         self._add_pos(name_length)
         
         result.append(INXEntry(result, name, content_start))
     return result
Exemplo n.º 2
0
Arquivo: fdt.py Projeto: rubyu/inx2csv
def read_vint(f, p):
    """
    Decodes variable-length format for position integers.
    http://lucene.apache.org/core/old_versioned_docs/versions/3_0_0/fileformats.html#VInt
    """
    eof = len(f)
    length = 0
    total = 0
    while True:
        if p == eof:
            raise EOFError()
        i = read_int(f, p, 1)
        has_remain = False
        if 0b10000000 <= i: #high-order bit is 1
            has_remain = True
            i = i ^ 0b10000000 #high-order bit to 0
        else:
            has_remain = False
        total = total | i << 7 * length #append low-order 7 bits to the result
        length += 1
        p += 1
        if not has_remain:
            break
    return VInt(length, total)