Example #1
0
def FileReadInteger(file_handle: io.BufferedRandom,
                    size: int = INT_VALUE) -> int:
    if size < CHAR_VALUE or size > INT_VALUE:
        raise Exception("Size error")
    return int.from_bytes(file_handle.read(size),
                          byteorder="little",
                          signed=False)
Example #2
0
def FileReadString(file_handle: io.BufferedRandom, length: int = -1) -> str:
    if file_handle.binflag:
        if length < 1:
            return ""
        return file_handle.read(
            len("a".encode(file_handle.encoding)) * length).decode(
                file_handle.encoding)
    return file_handle.readline(length)
Example #3
0
 def __init__(self, file: BufferedRandom) -> None:
     """Eine SaveFile Instanz der Generation 4
     
     Parameter
     ----------------
     ```py
     (BufferedRandom) file
     ```
     Die geöffnete Speicherdatei
     
     
     """
     self.File = file
     self.data = [x for x in file.read()]
     self.GeneralBlockPosition = self.GetActiveBlock(0, self.SmallBlockEnd)
     self.GeneralBlockStart = self.GeneralBlockPosition * self.PartitionSize
Example #4
0
    def read(self, path, offset, size):
        buf = None
        br = None
        conn = None
        try:
            conn, desc = self.session.data_objects.open(path, O_RDONLY)
            raw = iRODSDataObjectFileRaw(conn, desc)
            br = BufferedRandom(raw)
            new_offset = br.seek(offset)
            
            if new_offset == offset:
                buf = br.read(size)
        finally:
            if br:
                br.close()
            if conn:
                conn.release(True)

        return buf
Example #5
0
def read_frame_data(seekable_binary_stream: io.BufferedRandom):
    seekable_binary_stream.seek(0)
    header = seekable_binary_stream.read(2)
    if header != b'\xff\xd8':
        raise Exception
    size = None
    while size is None:
        marker = seekable_binary_stream.read(2)
        # fix marker reading position
        if marker[0] != 255 and marker[1] == 255:
            seekable_binary_stream.seek(-1, 1)
            marker = seekable_binary_stream.read(2)
        if marker == b'\xff\x00':
            raise ValueError("jpeg marker not found")
        if marker in START_OF_FRAME_MARKERS:
            seekable_binary_stream.seek(3, 1)
            size = struct.unpack('>HH', seekable_binary_stream.read(4))
            components = seekable_binary_stream.read(1)[0]
            component_scales = []
            subsampling = SUPPORTED_COLOR_SPACES.NONE
            for component in range(components):
                component_id = seekable_binary_stream.read(1)[0]
                colorspace_struct = seekable_binary_stream.read(1)[0]
                h = (colorspace_struct & 0xf0) >> 4
                v = colorspace_struct & 0x0f
                component_scales.append((h, v))
                seekable_binary_stream.seek(1, 1)
            if component_scales[0] == (2, 2):
                subsampling = SUPPORTED_COLOR_SPACES.YUV420
            elif component_scales[0] == (2, 1) or component_scales[0] == (1,
                                                                          2):
                subsampling = SUPPORTED_COLOR_SPACES.YUV422
            else:
                subsampling = SUPPORTED_COLOR_SPACES.YUV444
            return (size, subsampling)
        else:
            frame_len = struct.unpack('>H', seekable_binary_stream.read(2))[0]
            seekable_binary_stream.seek(frame_len - 2, 1)
Example #6
0
def FileReadDouble(file_handle: io.BufferedRandom) -> float:
    return struct.unpack("<d", file_handle.read(8))[0]
Example #7
0
def FileReadFloat(file_handle: io.BufferedRandom) -> float:
    return struct.unpack("<f", file_handle.read(4))[0]
Example #8
0
def FileReadLong(file_handle: io.BufferedRandom) -> int:
    return int.from_bytes(file_handle.read(8),
                          byteorder="little",
                          signed=False)