Project

General

Profile

Actions

Feature #10900

closed

GzipReader does not define `#external_encoding`

Added by akostadinov (Aleksandar Kostadinov) about 9 years ago. Updated almost 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:68287]

Description

Hello,

I want to store/load some yaml and other text data in gz for space efficiency. I thought it's most efficient to read/write directly to/from a gzip stream. But seems like the GzipReader io object does not support everything that a regular file io object does. I spotted the #external_encoding method. So for example to load YAML directly from gzip I use the following method:

    def load_yaml_from_gz(gz)
      loaded = nil
      Zlib::GzipReader.open(gz) do |f|
        class << f
          def external_encoding
            Encoding::UTF_8
          end
        end
        loaded = YAML.load(f, gz)
      end
      return loaded
    end

I need the monkey-patching because otherwise the YAML.load method fails for no #external_encoding method defined.

To avoid monkey patching just to read some text from a gzip archive I propose that GzipReader implements #external_encoding the same way as File does.

Actions #1

Updated by Anonymous almost 9 years ago

  • Status changed from Open to Closed

Applied in changeset r50460.


  • ext/zlib/zlib.c (rb_gzreader_external_encoding):
    define GzipReader#external_encoding.
    [Bug #10900]

  • test/zlib/test_zlib.rb: test for above.

Actions #2

Updated by usa (Usaku NAKAMURA) almost 9 years ago

  • Tracker changed from Bug to Feature
Actions #3

Updated by djberg96 (Daniel Berger) almost 9 years ago

I'd say it should add #encoding and #internal_encoding methods as well, since the constructor supports those options.

Updated by akostadinov (Aleksandar Kostadinov) almost 9 years ago

Daniel Berger wrote:

I'd say it should add #encoding and #internal_encoding methods as well, since the constructor supports those options.

I guess you have to file a separate feature request for that.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0