| 154 | } |
| 155 | |
| 156 | int SectionStream::seekFrom(int offset, SeekOrigin origin) |
| 157 | { |
| 158 | uint32_t newOffset = readOffset; |
| 159 | |
| 160 | if(currentSectionIndex < 0 || currentSectionIndex >= sectionCount) { |
| 161 | return -1; |
| 162 | } |
| 163 | auto& sect = sections[currentSectionIndex]; |
| 164 | |
| 165 | switch(origin) { |
| 166 | case SeekOrigin::Start: |
| 167 | newOffset = sect.start + offset; |
| 168 | break; |
| 169 | |
| 170 | case SeekOrigin::Current: |
| 171 | newOffset += offset; |
| 172 | break; |
| 173 | |
| 174 | case SeekOrigin::End: |
| 175 | newOffset = uint32_t(sect.end() + offset); |
| 176 | break; |
| 177 | |
| 178 | default: |
| 179 | return -1; |
| 180 | } |
| 181 | |
| 182 | if(newOffset < sect.start || newOffset > sect.end()) { |
| 183 | return -1; |
| 184 | } |
| 185 | |
| 186 | int pos = stream->seekFrom(newOffset, SeekOrigin::Start); |
| 187 | if(uint32_t(pos) != newOffset) { |
| 188 | return -1; |
| 189 | } |
| 190 | |
| 191 | readOffset = newOffset; |
| 192 | sectionOffset = newOffset - sect.start; |
| 193 | |
| 194 | if(newSection >= 0) { |
| 195 | // Prevent recursion |
| 196 | auto n = newSection; |
| 197 | newSection = -1; |
| 198 | gotoSection(n); |
| 199 | } |
| 200 | |
| 201 | return sectionOffset; |
| 202 | } |
no test coverage detected