-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First checkin for the implementation of Byte Ranges in Readium SDK (W…
…ORK IN PROGRESS) This is the first checkin for the implementation of Byte Ranges in Readium SDK. In short, the objective of adding Byte Ranges to Readium SDK is so that there is a way to deal with resources of great size inside an ePUB. For example, you may have an ePUB file with a 1 GB video file in it, and in that case you want to allow the client app to be able to read just chunks of bytes out of that video, and not have to put the entire 1 GB video in memory. This is still a work in progress. There are still code changes that we need to make, plus some more code cleanup that we want to do, before marking this as concluded. Following checkins will take care of that.
- Loading branch information
Showing
7 changed files
with
460 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
|
||
#import "RDPackageResource.h" | ||
#import <ePub3/archive.h> | ||
#import <ePub3/filter.h> | ||
#import <ePub3/filter_chain.h> | ||
#import <ePub3/package.h> | ||
#import <ePub3/utilities/byte_stream.h> | ||
#import "RDPackage.h" | ||
|
@@ -37,6 +39,7 @@ | |
@interface RDPackageResource() { | ||
@private ePub3::ByteStream *m_byteStream; | ||
@private NSUInteger m_contentLength; | ||
@private UInt64 m_offset; | ||
} | ||
|
||
@end | ||
|
@@ -105,19 +108,31 @@ - (void)dealloc { | |
|
||
|
||
- (NSData *)readDataOfLength:(NSUInteger)length { | ||
NSMutableData *md = [[NSMutableData alloc] initWithCapacity:length == 0 ? 1 : length]; | ||
NSUInteger totalRead = 0; | ||
|
||
while (totalRead < length) { | ||
NSUInteger thisLength = MIN(sizeof(m_buffer), length - totalRead); | ||
std::size_t count = m_byteStream->ReadBytes(m_buffer, thisLength); | ||
totalRead += count; | ||
[md appendBytes:m_buffer length:count]; | ||
|
||
if (count != thisLength) { | ||
NSLog(@"Did not read the expected number of bytes! (%lu %lu)", | ||
count, (unsigned long)thisLength); | ||
break; | ||
NSMutableData *md = [[NSMutableData alloc] initWithCapacity:length]; | ||
|
||
ePub3::ByteRangeFilterSyncStream *filterStream = | ||
dynamic_cast<ePub3::ByteRangeFilterSyncStream *>(m_byteStream); | ||
|
||
if (filterStream == nullptr) { | ||
NSLog(@"The byte stream is not a FilterChainSyncStream!"); | ||
} | ||
else { | ||
ePub3::ByteRange range; | ||
range.Location(m_offset); | ||
NSUInteger totalRead = 0; | ||
|
||
while (totalRead < length) { | ||
range.Length(MIN(sizeof(m_buffer), length - totalRead)); | ||
std::size_t count = filterStream->ReadBytes(m_buffer, sizeof(m_buffer), range); | ||
[md appendBytes:m_buffer length:count]; | ||
totalRead += count; | ||
range.Location(range.Location() + count); | ||
|
||
if (count != range.Length()) { | ||
This comment has been minimized.
Sorry, something went wrong.
danielweck
Member
|
||
NSLog(@"Did not read the expected number of bytes! (%lu %lu)", | ||
count, (unsigned long)range.Length()); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -126,12 +141,13 @@ - (NSData *)readDataOfLength:(NSUInteger)length { | |
|
||
|
||
- (void)setOffset:(UInt64)offset { | ||
ePub3::SeekableByteStream* seekStream = dynamic_cast<ePub3::SeekableByteStream*>(m_byteStream); | ||
ePub3::ByteStream::size_type pos = seekStream->Seek(offset, std::ios::beg); | ||
m_offset = offset; | ||
} | ||
|
||
if (pos != offset) { | ||
NSLog(@"Setting the byte stream offset failed! pos = %lu, offset = %llu", pos, offset); | ||
} | ||
- (BOOL)isByteRangeResource | ||
{ | ||
ePub3::ByteRangeFilterSyncStream *filterStream = dynamic_cast<ePub3::ByteRangeFilterSyncStream *>(m_byteStream); | ||
return (filterStream != nullptr); | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
I hope you don't mind, I added the missing Package API (so I can test this feature branch with LauncherOSX):
e7b7d62