Read-only wrapper for streaming blob content. Supports reading both raw and filtered blob content. Implements io.BufferedReader. Example: >>> with BlobIO(blob) as f: ... while True: ... # Read blob data in 1KB chunks until EOF is reached ...
| 97 | |
| 98 | |
| 99 | class BlobIO(io.BufferedReader, AbstractContextManager): |
| 100 | """Read-only wrapper for streaming blob content. |
| 101 | |
| 102 | Supports reading both raw and filtered blob content. |
| 103 | Implements io.BufferedReader. |
| 104 | |
| 105 | Example: |
| 106 | |
| 107 | >>> with BlobIO(blob) as f: |
| 108 | ... while True: |
| 109 | ... # Read blob data in 1KB chunks until EOF is reached |
| 110 | ... chunk = f.read(1024) |
| 111 | ... if not chunk: |
| 112 | ... break |
| 113 | |
| 114 | By default, `BlobIO` will stream the raw contents of the blob, but it |
| 115 | can also be used to stream filtered content (i.e. to read the content |
| 116 | after applying filters which would be used when checking out the blob |
| 117 | to the working directory). |
| 118 | |
| 119 | Example: |
| 120 | |
| 121 | >>> with BlobIO(blob, as_path='my_file.ext') as f: |
| 122 | ... # Read the filtered content which would be returned upon |
| 123 | ... # running 'git checkout -- my_file.txt' |
| 124 | ... filtered_data = f.read() |
| 125 | """ |
| 126 | |
| 127 | def __init__( |
| 128 | self, |
| 129 | blob: Blob, |
| 130 | as_path: Optional[str] = None, |
| 131 | flags: BlobFilter = BlobFilter.CHECK_FOR_BINARY, |
| 132 | commit_id: Optional[Oid] = None, |
| 133 | ): |
| 134 | """Wrap the specified blob. |
| 135 | |
| 136 | Parameters: |
| 137 | blob: The blob to wrap. |
| 138 | as_path: Filter the contents of the blob as if it had the specified |
| 139 | path. If `as_path` is None, the raw contents of the blob will |
| 140 | be read. |
| 141 | flags: A combination of enums.BlobFilter constants |
| 142 | (only applicable when `as_path` is set). |
| 143 | commit_id: Commit to load attributes from when |
| 144 | ATTRIBUTES_FROM_COMMIT is specified in `flags` |
| 145 | (only applicable when `as_path` is set). |
| 146 | """ |
| 147 | raw = _BlobIO(blob, as_path=as_path, flags=flags, commit_id=commit_id) |
| 148 | super().__init__(raw) |
| 149 | |
| 150 | def __exit__(self, exc_type, exc_value, traceback): |
| 151 | self.close() |
| 152 | |
| 153 | |
| 154 | io.RawIOBase.register(_BlobIO) |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…