System.util.zlib.ZInflaterInputStream.Read C# (CSharp) Méthode

Read() public méthode

public Read ( byte b, int off, int len ) : int
b byte
off int
len int
Résultat int
        public override int Read(byte[] b, int off, int len)
        {
            if(len==0)
                return(0);
            int err;
            z.next_out=b;
            z.next_out_index=off;
            z.avail_out=len;
            do {
                if((z.avail_in==0)&&(!nomoreinput)) { // if buffer is empty and more input is avaiable, refill it
                    z.next_in_index=0;
                    z.avail_in=inp.Read(buf, 0, BUFSIZE);//(BUFSIZE<z.avail_out ? BUFSIZE : z.avail_out));
                    if(z.avail_in<=0) {
                        z.avail_in=0;
                        nomoreinput=true;
                    }
                }
                err=z.inflate(flushLevel);
                if(nomoreinput&&(err==JZlib.Z_BUF_ERROR))
                    return(0);
                if(err!=JZlib.Z_OK && err!=JZlib.Z_STREAM_END)
                    throw new IOException("inflating: "+z.msg);
                if((nomoreinput||err==JZlib.Z_STREAM_END)&&(z.avail_out==len))
                    return(0);
            }
            while(z.avail_out==len&&err==JZlib.Z_OK);
            //System.err.print("("+(len-z.avail_out)+")");
            return(len-z.avail_out);
        }

Usage Example

Exemple #1
0
 /** A helper to FlateDecode.
 * @param in the input data
 * @param strict <CODE>true</CODE> to read a correct stream. <CODE>false</CODE>
 * to try to read a corrupted stream
 * @return the decoded data
 */    
 public static byte[] FlateDecode(byte[] inp, bool strict) {
     MemoryStream stream = new MemoryStream(inp);
     ZInflaterInputStream zip = new ZInflaterInputStream(stream);
     MemoryStream outp = new MemoryStream();
     byte[] b = new byte[strict ? 4092 : 1];
     try {
         int n;
         while ((n = zip.Read(b, 0, b.Length)) > 0) {
             outp.Write(b, 0, n);
         }
         zip.Close();
         outp.Close();
         return outp.ToArray();
     }
     catch {
         if (strict)
             return null;
         return outp.ToArray();
     }
 }