| 1 |
/** |
|---|
| 2 |
* Authors: Frank Benoit <keinfarbton@googlemail.com> |
|---|
| 3 |
*/ |
|---|
| 4 |
module dwt.dwthelper.InflaterInputStream; |
|---|
| 5 |
|
|---|
| 6 |
public import dwt.dwthelper.InputStream; |
|---|
| 7 |
import dwt.dwthelper.utils; |
|---|
| 8 |
import tango.io.Stdout; |
|---|
| 9 |
import tango.io.compress.ZlibStream; |
|---|
| 10 |
version(Windows){ |
|---|
| 11 |
version(build){ |
|---|
| 12 |
pragma(link,"zlib"); |
|---|
| 13 |
} |
|---|
| 14 |
} |
|---|
| 15 |
version(TANGOSVN){ |
|---|
| 16 |
import tango.io.device.Conduit; |
|---|
| 17 |
} else { |
|---|
| 18 |
import tango.io.Conduit; |
|---|
| 19 |
} |
|---|
| 20 |
|
|---|
| 21 |
class InputStreamWrapper : tango.io.model.IConduit.InputStream { |
|---|
| 22 |
|
|---|
| 23 |
dwt.dwthelper.InputStream.InputStream istr; |
|---|
| 24 |
|
|---|
| 25 |
this( dwt.dwthelper.InputStream.InputStream istr ){ |
|---|
| 26 |
this.istr = istr; |
|---|
| 27 |
} |
|---|
| 28 |
|
|---|
| 29 |
uint read (void[] dst){ |
|---|
| 30 |
int res = istr.read( cast(byte[])dst ); |
|---|
| 31 |
return res; |
|---|
| 32 |
} |
|---|
| 33 |
void[] load (void[] dst = null) { |
|---|
| 34 |
return Conduit.load (this, dst); |
|---|
| 35 |
} |
|---|
| 36 |
|
|---|
| 37 |
tango.io.model.IConduit.InputStream clear (){ |
|---|
| 38 |
return this; |
|---|
| 39 |
} |
|---|
| 40 |
|
|---|
| 41 |
tango.io.model.IConduit.IConduit conduit (){ |
|---|
| 42 |
return null; |
|---|
| 43 |
} |
|---|
| 44 |
|
|---|
| 45 |
void close (){ |
|---|
| 46 |
istr.close(); |
|---|
| 47 |
} |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
public class InflaterInputStream : dwt.dwthelper.InputStream.InputStream { |
|---|
| 51 |
|
|---|
| 52 |
alias dwt.dwthelper.InputStream.InputStream.read read; |
|---|
| 53 |
alias dwt.dwthelper.InputStream.InputStream.skip skip; |
|---|
| 54 |
alias dwt.dwthelper.InputStream.InputStream.available available; |
|---|
| 55 |
alias dwt.dwthelper.InputStream.InputStream.close close; |
|---|
| 56 |
alias dwt.dwthelper.InputStream.InputStream.mark mark; |
|---|
| 57 |
alias dwt.dwthelper.InputStream.InputStream.reset reset; |
|---|
| 58 |
alias dwt.dwthelper.InputStream.InputStream.markSupported markSupported; |
|---|
| 59 |
|
|---|
| 60 |
protected byte[] buf; |
|---|
| 61 |
protected int len; |
|---|
| 62 |
package bool usesDefaultInflater = false; |
|---|
| 63 |
|
|---|
| 64 |
ZlibInput tangoIstr; |
|---|
| 65 |
|
|---|
| 66 |
public this ( dwt.dwthelper.InputStream.InputStream istr ){ |
|---|
| 67 |
tangoIstr = new ZlibInput( new InputStreamWrapper(istr )); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
public int read(){ |
|---|
| 71 |
ubyte[1] data; |
|---|
| 72 |
uint res = tangoIstr.read( data ); |
|---|
| 73 |
if( res !is 1 ){ |
|---|
| 74 |
return data[0] & 0xFF; |
|---|
| 75 |
} |
|---|
| 76 |
return -1; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
public int read( byte[] b, int off, int len ){ |
|---|
| 80 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 81 |
return 0; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
public int available(){ |
|---|
| 85 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 86 |
return 0; |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
public long skip( long n ){ |
|---|
| 90 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 91 |
return 0L; |
|---|
| 92 |
} |
|---|
| 93 |
|
|---|
| 94 |
public void close(){ |
|---|
| 95 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
public void fill(){ |
|---|
| 99 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 100 |
} |
|---|
| 101 |
|
|---|
| 102 |
public bool markSupported(){ |
|---|
| 103 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 104 |
return false; |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
public synchronized void mark( int readlimit ){ |
|---|
| 108 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
public synchronized void reset(){ |
|---|
| 112 |
implMissing( __FILE__, __LINE__ ); |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|