-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstream.py
More file actions
27 lines (19 loc) · 738 Bytes
/
stream.py
File metadata and controls
27 lines (19 loc) · 738 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python
# coding: utf-8
from typing import BinaryIO
u1 = u2 = u4 = int
class Stream(object):
def __init__(self, file: BinaryIO):
self.file = file
def tell(self):
return self.file.tell()
def read_s4(self) ->int:
return int.from_bytes(self.file.read(4), byteorder="big", signed=True)
def read_u1(self) -> u1:
return int.from_bytes(self.file.read(1), byteorder='big', signed=False)
def read_u2(self) -> u2:
return int.from_bytes(self.file.read(2), byteorder='big', signed=False)
def read_u4(self) -> u4:
return int.from_bytes(self.file.read(4), byteorder='big', signed=False)
def read_bytes(self, n) -> bytes:
return self.file.read(n)