lib/ruby/truffle/pr-zlib/lib/pr/rbzlib.rb
#    Sets the starting position for the next gzread or gzwrite on the given
# compressed file. The offset represents a number of bytes in the
#    gzseek returns the resulting offset location as measured in bytes from
# the beginning of the uncompressed stream, or -1 in case of error.
#    SEEK_END is not implemented, returns error.
#    In this version of the library, gzseek can be extremely slow.
Sets the starting position for the next gzread or gzwrite on the given
compressed file. The offset represents a number of bytes in the
gzseek returns the resulting offset location as measured in bytes from
the beginning of the uncompressed stream, or -1 in case of error.
SEEK_END is not implemented, returns error.
In this version of the library, gzseek can be extremely slow.
Sets the starting position for the next gzread or gzwrite on the given compressed file . The offset represents a number of bytes in the gzseek returns the resulting offset location as measured in bytes from the beginning of the uncompressed stream or - 1 in case of error . SEEK_END is not implemented returns error . In this version of the library gzseek can be extremely slow .
def gzseek(file,offset,whence)
    s = file
    if s.nil? || (whence == SEEK_END) || (s.z_err == Z_ERRNO) ||
           (s.z_err == Z_DATA_ERROR)
      return(-1)
    end
    if (s.mode == 'w')
      if (whence == SEEK_SET)
        offset -= s.in
      end
      if (offset < 0)
        return(-1)
      end
      if (s.inbuf.nil?)
        s.inbuf = 0.chr*Z_BUFSIZE
      end
      while (offset > 0)
        size = Z_BUFSIZE
        if (offset < Z_BUFSIZE)
          size = (offset)
        end
        size = gzwrite(file, s.inbuf, size)
        if size == 0
          return(-1)
        end
        offset -= size
      end
      return(s.in)
    end
    if (whence == SEEK_CUR)
      offset += s.out
    end
    if (offset < 0)
      return(-1)
    end
    if s.transparent
      s.back = Z_EOF
      s.stream.avail_in = 0
      s.stream.next_in = Bytef.new(s.inbuf)
      s.file.seek(offset, SEEK_SET)
      s.in = offset
      s.out = offset
      return offset
    end
    if (offset >= s.out)
      offset -= s.out
    elsif (gzrewind(file) < 0)
      return(-1)
    end
    if offset != 0 && s.outbuf.nil?
      s.outbuf = 0.chr * Z_BUFSIZE
    end
    if(offset != 0 && s.back != Z_EOF)
      s.back = Z_EOF
      s.out += 1
      offset -= 1
      s.z_err = Z_STREAM_END if s.last
    end
    while (offset > 0)
      size = Z_BUFSIZE
      if (offset < Z_BUFSIZE)
        size = (offset)
      end
      size = gzread(file, s.outbuf, size)
      if (size <= 0)
        return(-1)
      end
      offset -= size
    end
    return(s.out)
  end
def gzseek ( file , offset , whence ) s = file if s . nil? || ( whence == SEEK_END ) || ( s . z_err == Z_ERRNO ) || ( s . z_err == Z_DATA_ERROR ) return ( - 1 ) end if ( s . mode == 'w' ) if ( whence == SEEK_SET ) offset -= s . in end if ( offset < 0 ) return ( - 1 ) end if ( s . inbuf . nil? ) s . inbuf = 0 . chr * Z_BUFSIZE end while ( offset > 0 ) size = Z_BUFSIZE if ( offset < Z_BUFSIZE ) size = ( offset ) end size = gzwrite ( file , s . inbuf , size ) if size == 0 return ( - 1 ) end offset -= size end return ( s . in ) end if ( whence == SEEK_CUR ) offset += s . out end if ( offset < 0 ) return ( - 1 ) end if s . transparent s . back = Z_EOF s . stream . avail_in = 0 s . stream . next_in = Bytef . new ( s . inbuf ) s . file . seek ( offset , SEEK_SET ) s . in = offset s . out = offset return offset end if ( offset >= s . out ) offset -= s . out elsif ( gzrewind ( file ) < 0 ) return ( - 1 ) end if offset != 0 && s . outbuf . nil? s . outbuf = 0 . chr * Z_BUFSIZE end if ( offset != 0 && s . back != Z_EOF ) s . back = Z_EOF s . out += 1 offset -= 1 s . z_err = Z_STREAM_END if s . last end while ( offset > 0 ) size = Z_BUFSIZE if ( offset < Z_BUFSIZE ) size = ( offset ) end size = gzread ( file , s . outbuf , size ) if ( size <= 0 ) return ( - 1 ) end offset -= size end return ( s . out ) end
Sets the starting position for the next gzread or gzwrite on the given
compressed file.
Sets the starting position for the next gzread or gzwrite on the given compressed file .
file
<not_specific>
offset
<not_specific>
whence
<not_specific>