Thread Rating:
  • 3 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 My Feature Ideas
ZiNgA BuRgA Offline
Fag
*******
Posts: 3,357
Joined: Jan 2008
Post: #20
RE: My Feature Ideas
I think I'll ditch gzip in XThreads attachments. (and I kinda wanted this)

The stupid HTTP specification fails to mention the ordering which Content-Encoding and Content-Range should be applied in.  And it's hard to find any info on this via Google.
But I did manage to find something after quite a bit of searching.  Apparently, it's compression then range selection, though IDK about the support of clients/download managers for this are:
http://www.mail-archive.com/www-talk@w3....http://www.mail-archive.com/www-talk@w3.org/msg

Which makes things a little tricky:
  • If I store the file uncompressed, there is no way to to select the range as I cannot generate compressed data from a specified range.  Compressing the entire file up to the range may be possible (difficult because PHP doesn't provide all the zlib APIs), but absurdly slow
  • If I store the file compressed, everything works well, except if a client doesn't support gzip content-encoding, and decides to use ranged requests.  This wouldn't be a problem if gzseek wasn't slow.
  • All problems are solved if the file is stored both compressed and uncompressed - except for the fact that this increases the amount of disk space used
  • If PHP exposed all of zlib's API, it may be possible to force deflate block splits mid-stream - this would be somewhat of a tradeoff in that you'd get a slight bit of slowness (but this is limited because you only need to start decompressing from the start of the block rather than the start of the file) and less compression efficiency (due to forcing block boundaries).  Nonetheless, would be difficult to implement, and would require managing an index (yuck)
    EDIT: actually, this may be possible with a bit of fiddling around with binary strings.  I still think it's yucky, but doable perhaps.
  • I could offer a tradeoff - enable gzip and disable ranged requests; maybe offer such an option to smaller (uncompressed?) files

Also, PHP doesn't offer a way to compress in chunks (like zlib) - you can only compress the whole data at once.
None of these work:

PHP Code:
fopen('compress.zlib://php://output', 'wb');
gzopen('php://output', 'wb');


However, a workaround may be to use stream_filter_append: http://php.net/manual/en/filters.compression.php
Will only work on PHP 5.1.0 and higher.  Gzip headers can be outputted, the rest through something like:

PHP Code:
$fp = fopen('php://output', 'wb');
stream_filter_append($fp, 'zlib.deflate', STREAM_FILTER_WRITE, 6);
fwrite($fp, $data);
fclose($fp);

The remaining difficulty would be calculating the CRC32 in chunks, but this can probably be reasonably done by porting zlib's crc32_combine function.

Ah well.


My Blog
(This post was last modified: 12-14-2010 10:40 AM by ZiNgA BuRgA.)
12-14-2010 10:38 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
My Feature Ideas - ZiNgA BuRgA - 12-08-2010, 09:00 PM
RE: My Feature Ideas - Imran - 12-08-2010, 11:41 PM
RE: My Feature Ideas - RateU - 12-09-2010, 06:52 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-09-2010, 08:49 AM
RE: My Feature Ideas - RocketFoot - 12-09-2010, 10:49 PM
RE: My Feature Ideas - RateU - 12-10-2010, 06:12 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-10-2010, 09:01 AM
RE: My Feature Ideas - RateU - 12-10-2010, 12:12 PM
RE: My Feature Ideas - leefish - 12-10-2010, 12:44 PM
RE: My Feature Ideas - ZiNgA BuRgA - 12-10-2010, 10:05 PM
RE: My Feature Ideas - leefish - 12-11-2010, 01:58 AM
RE: My Feature Ideas - RateU - 12-11-2010, 04:11 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-12-2010, 10:34 AM
RE: My Feature Ideas - RateU - 12-13-2010, 07:35 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-13-2010, 08:34 AM
RE: My Feature Ideas - RateU - 12-14-2010, 01:57 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-14-2010, 09:37 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-14-2010 10:38 AM
RE: My Feature Ideas - leefish - 12-15-2010, 01:16 AM
RE: My Feature Ideas - ZiNgA BuRgA - 12-15-2010, 08:27 AM
RE: My Feature Ideas - RateU - 01-25-2011, 08:52 AM
RE: My Feature Ideas - ZiNgA BuRgA - 01-25-2011, 04:42 PM
RE: My Feature Ideas - RateU - 01-26-2011, 04:17 AM
RE: My Feature Ideas - ZiNgA BuRgA - 01-26-2011, 08:24 AM
RE: My Feature Ideas - RocketFoot - 01-29-2011, 07:52 AM
RE: My Feature Ideas - ZiNgA BuRgA - 01-29-2011, 11:11 AM
RE: My Feature Ideas - leefish - 01-29-2011, 11:49 AM
RE: My Feature Ideas - ZiNgA BuRgA - 01-29-2011, 08:47 PM
RE: My Feature Ideas - RateU - 01-31-2011, 09:38 AM
RE: My Feature Ideas - RateU - 10-25-2011, 08:02 AM
RE: My Feature Ideas - ZiNgA BuRgA - 10-25-2011, 12:21 PM
RE: My Feature Ideas - Sama34 - 10-25-2011, 02:40 PM
RE: My Feature Ideas - RateU - 10-26-2011, 05:37 AM
RE: My Feature Ideas - RateU - 10-27-2011, 06:57 AM
RE: My Feature Ideas - RateU - 01-15-2012, 06:45 AM
RE: My Feature Ideas - ZiNgA BuRgA - 01-15-2012, 09:48 AM
RE: My Feature Ideas - RateU - 01-16-2012, 02:24 AM
RE: My Feature Ideas - ZiNgA BuRgA - 01-16-2012, 10:14 AM
RE: My Feature Ideas - RateU - 01-17-2012, 01:20 AM
RE: My Feature Ideas - leefish - 04-27-2012, 05:06 PM
RE: My Feature Ideas - ZiNgA BuRgA - 04-27-2012, 10:10 PM
RE: My Feature Ideas - leefish - 04-28-2012, 01:36 AM
RE: My Feature Ideas - ZiNgA BuRgA - 04-28-2012, 09:32 AM
RE: My Feature Ideas - brad-t - 07-10-2012, 12:58 AM
RE: My Feature Ideas - ZiNgA BuRgA - 07-10-2012, 08:29 AM
RE: My Feature Ideas - brad-t - 07-10-2012, 11:11 PM
RE: My Feature Ideas - ZiNgA BuRgA - 07-10-2012, 11:36 PM
RE: My Feature Ideas - brad-t - 10-13-2012, 04:31 AM
RE: My Feature Ideas - brad-t - 07-11-2012, 05:07 AM
RE: My Feature Ideas - brad-t - 10-23-2012, 11:55 PM
RE: My Feature Ideas - ZiNgA BuRgA - 10-24-2012, 08:22 AM
RE: My Feature Ideas - brad-t - 10-25-2012, 05:24 AM

 Standard Tools
Forum Jump: