def get_header(self, filename=None): f = self.fileobj f.seek(0) self.__check_header(f) self.__offset = self.__find_audio_offset(f) data = bytearray(b'fLaC') for block in self.metadata_blocks: if isinstance(block, Padding): continue data += MetadataBlock._writeblock(block) padding = Padding() padding.length = 1020 data += MetadataBlock._writeblock(padding, is_last=True) return bytes(data)
def test_write_read_max_size(self): class SomeBlock(MetadataBlock): code = 255 max_data_size = 2**24 - 1 block = SomeBlock(b"\x00" * max_data_size) data = MetadataBlock._writeblock(block) self.assertEqual(data[:4], b"\xff\xff\xff\xff") header_size = 4 self.assertEqual(len(data), max_data_size + header_size) block = SomeBlock(b"\x00" * (max_data_size + 1)) self.assertRaises(error, MetadataBlock._writeblock, block)
def test_write_read_max_size(self): class SomeBlock(MetadataBlock): code = 255 max_data_size = 2 ** 24 - 1 block = SomeBlock(b"\x00" * max_data_size) data = MetadataBlock._writeblock(block) self.assertEqual(data[:4], b"\xff\xff\xff\xff") header_size = 4 self.assertEqual(len(data), max_data_size + header_size) block = SomeBlock(b"\x00" * (max_data_size + 1)) self.assertRaises(error, MetadataBlock._writeblock, block)