Browse files

Revert "Rudimentary gzip" (accidentally committed)

This reverts commit aa2f338.
  • Loading branch information...
1 parent c85408f commit 593a0229b65b2431f7d5299d130358b1066d5646 @carlobaldassi carlobaldassi committed Oct 22, 2012
Showing with 0 additions and 130 deletions.
  1. +0 −1 base/export.jl
  2. +0 −6 base/process.jl
  3. +0 −123 extras/zlib.jl
View
1 base/export.jl
@@ -1206,7 +1206,6 @@ export
cmd_stdout_stream,
cmds,
connect,
- dup,
dup2,
exec,
fork,
View
6 base/process.jl
@@ -142,12 +142,6 @@ function dup2(fd1::FileDes, fd2::FileDes)
system_error(:dup2, ret == -1)
end
-function dup(fd::FileDes)
- ret = ccall(:dup, Int32, (Int32,), fd.fd)
- system_error(:dup, ret == -1)
- return FileDes(ret)
-end
-
function close(fd::FileDes)
ret = ccall(:close, Int32, (Int32,), fd.fd)
system_error(:close, ret != 0)
View
123 extras/zlib.jl
@@ -17,9 +17,6 @@ export
uncompress,
uncompress_to_buffer,
-# gz files interface
- gzopen,
-
# ZError, related constants (zlib_h.jl)
ZError,
Z_ERRNO,
@@ -124,124 +121,4 @@ function uncompress_to_buffer(source::Array{Uint8}, dest::Array{Uint8})
return dest_buf_size[1]
end
-type GzStream <: IO
- gzstruct::Ptr{Void}
- name::String
- read_buffer::Vector{Uint8}
- read_buffer_size::Int
- read_buffer_pos::Int
- function GzStream(struct, name)
- new(struct, name, Array(Uint8, Z_DEFAULT_BUFSIZE), 0, 0)
- end
-end
-
-show(io, s::GzStream) = print(io, "GzStream(", s.name, ")")
-
-function gzopen(path::String, mode::String)
- if mode != "rb" && mode != "wb"
- error("unsupported gzopen mode: ", mode)
- end
- if mode == "rb"
- fmode = "r"
- elseif mode == "wb"
- fmode = "w"
- end
- f = open(path, fmode)
- fdes = int32(fd(f))
- fdes_dup = dup(FileDes(fdes))
- close(f)
- struct = ccall(dlsym(_zlib, :gzdopen), Ptr{Void}, (Int32, Ptr{Uint8}), fdes_dup.fd, bytestring(mode))
- if struct == C_NULL
- error("gzopen: failed to open file: $path")
- end
- return GzStream(struct, strcat("<file ", path, ">"))
-end
-
-function gzopen(f::Function, args...)
- io = gzopen(args...)
- x = try f(io) catch err
- close(io)
- throw(err)
- end
- close(io)
- return x
-end
-
-function close(gzs::GzStream)
- if gzs.gzstruct == C_NULL
- return
- end
- ret = ccall(dlsym(_zlib, :gzclose), Int32, (Ptr{Void},), gzs.gzstruct)
- if ret != Z_OK
- error("error closing GzStream")
- end
- gzs.gzstruct = C_NULL
- gzs.name = strcat("[CLOSED] ", gzs.name)
- return
-end
-
-function write(gzs::GzStream, x::Uint8)
- ret = ccall(dlsym(_zlib, :gzputc), Int32, (Ptr{Void,}, Int32), gzs.gzstruct, x)
- if ret == -1
- error("gzwrite failed")
- end
- return
-end
-
-function _gzread_chunk(s::GzStream)
- ret = ccall(dlsym(_zlib, :gzread), Int32, (Ptr{Void}, Ptr{Void}, Int32), s.gzstruct, pointer(s.read_buffer), Z_DEFAULT_BUFSIZE)
- if ret == -1
- error("gzread failed")
- end
- s.read_buffer_size = ret
- s.read_buffer_pos = 1
- return
-end
-
-function read(s::GzStream, x::Type{Uint8})
- if s.read_buffer_pos == 0
- _gzread_chunk(s)
- end
- if s.read_buffer_size == 0
- error("gzread: end of file") # XXX?
- end
- ret = s.read_buffer[s.read_buffer_pos]
- s.read_buffer_pos += 1
- if s.read_buffer_pos > s.read_buffer_size
- s.read_buffer_pos = 0
- end
- return ret
-end
-
-function eof(s::GzStream)
- if s.read_buffer_pos == 0
- return ccall(dlsym(_zlib, :gzeof), Int32, (Ptr{Void},), s.gzstruct) == 1
- else
- return false
- end
-end
-
-readline(s::GzStream) = readuntil(s, '\n')
-
-function readuntil(s::GzStream, delim::Char)
- dest = memio()
- while !eof(s)
- c = char(read(s, Uint8))
- print(dest, c)
- if c == delim
- break
- end
- end
- takebuf_string(dest)
-end
-
-function readall(s::GzStream)
- dest = memio()
- while !eof(s)
- c = char(read(s, Uint8))
- print(dest, c)
- end
- takebuf_string(dest)
-end
-
end # module Zlib

0 comments on commit 593a022

Please sign in to comment.