Can't read from GzipReader: undefined method `external_encoding' #105

ghostganz opened this Issue Nov 25, 2012 · 3 comments

3 participants


I was doing this successfully with Ruby 1.9.2 and Syck:

require 'zlib'
require 'yaml'
data = YAML.load('foo.yml.gz'))

but with Psych it fails like this:

NoMethodError: undefined method `external_encoding' for #<Zlib::GzipReader:0x007fa36303ffa8>

so it looks like it's assuming things about the input stream that aren't always true.


@ghostganz Because you sent it the Zlib::GzipReader object and didn't read the file to a string.

require 'zlib'
require 'yaml'
data = YAML.load('foo.yml.gz')).read)

But I don't want to read it to a string, that was the point. Working with input streams directly used to work with Syck, but now it doesn't with Psych.


any update? why not allow reading yaml from a stream? This is most natural and memory efficient. After all it can read from a file stream, why not from a zstream?

hey, monkey patch workaround for the rescue:

    def load_yaml_from_gz(gz)
      loaded = nil do |f|
        class << f
          def external_encoding
        loaded = YAML.load(f, gz)
      return loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment