Bz2FileLoader¶
- class torchdata.datapipes.iter.Bz2FileLoader(datapipe: Iterable[Tuple[str, BufferedIOBase]], length: int = - 1)¶
Decompresses bz2 binary streams from an Iterable DataPipe which contains tuples of path name and bz2 binary streams, and yields a tuple of path name and extracted binary stream (functional name:
load_from_bz2
).- Parameters:
datapipe – Iterable DataPipe that provides tuples of path name and bz2 binary stream
length – Nominal length of the DataPipe
Note
The opened file handles will be closed automatically if the default
DecoderDataPipe
is attached. Otherwise, user should be responsible to close file handles explicitly or let Python’s GC close them periodically.Example
>>> from torchdata.datapipes.iter import FileLister, FileOpener >>> datapipe1 = FileLister(".", "*.bz2") >>> datapipe2 = FileOpener(datapipe1, mode="b") >>> bz2_loader_dp = datapipe2.load_from_bz2() >>> for _, stream in bz2_loader_dp: >>> print(stream.read()) b'0123456789abcdef'