示例#1
0
 def __init__(
         self,
         theFile,
         theFileId=None,
         keepGoing=False,
         hasTif=False,
         thePrLen=PhysRec.PR_MAX_LENGTH,
         thePrt=PhysRec.PhysRecTail(),
 ):
     """Constructor with:
     theFile - A file like object or string, if the latter it assumed to be a path.
     theFileId - File identifier, this could be a path for example. If None the RawStream will try and cope with it.
     keepGoing - If True we do our best to keep going.
     hasTif - Insert TIF markers or not.
     thePrLen - Max Physical Record length, defaults to the maximum possible length.
     thePrt - Physical Records Trailer settings (defaults to PhysRec.PhysRecTail()).
     """
     super().__init__(theFile, theFileId, 'w', keepGoing)
     try:
         self._prh = PhysRec.PhysRecWrite(
             self.file,
             self.fileId,
             self.keepGoing,
             hasTif,
             thePrLen,
             thePrt,
         )
     except PhysRec.ExceptionPhysRec as e:
         raise ExceptionFileWrite('FileWrite.__init__(): error "%s"' %
                                  str(e))
示例#2
0
 def setup(self, arg):
     pr_len, lr_len, lr_count = tuple(int(s) for s in arg.split('-'))
     self.io_file = io.BytesIO()
     pr_writer = PhysRec.PhysRecWrite(
         self.io_file,
         theFileId='WriteFile',
         keepGoing=False,
         hasTif=True,
         thePrLen=pr_len,
         thePrt=PhysRec.PhysRecTail(hasRecNum=True, fileNum=42, hasCheckSum=True),
     )
     for i in range(lr_count):
         pr_writer.writeLr(b'\xff' * lr_len)
示例#3
0
 def setup(self, arg):
     pr_len, lr_len, lr_count = tuple(int(s) for s in arg.split('-'))
     io_file = io.BytesIO()
     self.pr_writer = PhysRec.PhysRecWrite(
         io_file,
         theFileId='WriteFile',
         keepGoing=False,
         hasTif=False,
         thePrLen=pr_len,
         thePrt=PhysRec.PhysRecTail(
             hasRecNum=True,
             fileNum=42,
             hasCheckSum=False
         ),
     )
     self.logical_data = b'\xff' * lr_len
示例#4
0
def write_logical_data_to_physical_records(
    logical_data_records: typing.List[bytes],
    has_tif: bool = False,
    pr_len: int = PhysRec.PR_MAX_LENGTH,
    pr_tail: PhysRec.PhysRecTail = PhysRec.PhysRecTail()
) -> io.BytesIO:
    """
    Takes logical data and writes it into a contiguous set of physical records returning a binary file.
    This is quite useful for testing.

    pr_tail has the following arguments: hasRecNum=False, fileNum=None, hasCheckSum=False
    """
    file_obj = io.BytesIO()
    prh = PhysRec.PhysRecWrite(file_obj,
                               theFileId=None,
                               keepGoing=False,
                               hasTif=has_tif,
                               thePrLen=pr_len,
                               thePrt=pr_tail)
    for ld in logical_data_records:
        prh.writeLr(ld)
    return file_obj