Method: Sprockets::EncodingUtils#unmarshaled_deflated
- Defined in:
- lib/sprockets/encoding_utils.rb
#unmarshaled_deflated(str, window_bits = -Zlib::MAX_WBITS)) ⇒ Object
Internal: Unmarshal optionally deflated data.
Checks leading marshal header to see if the bytes are uncompressed otherwise inflate the data an unmarshal.
str - Marshaled String window_bits - Integer deflate window size. See ZLib::Inflate.new()
Returns unmarshaled Object or raises an Exception.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sprockets/encoding_utils.rb', line 38 def unmarshaled_deflated(str, window_bits = -Zlib::MAX_WBITS) major, minor = str[0], str[1] if major && major.ord == Marshal::MAJOR_VERSION && minor && minor.ord <= Marshal::MINOR_VERSION marshaled = str else begin marshaled = Zlib::Inflate.new(window_bits).inflate(str) rescue Zlib::DataError marshaled = str end end Marshal.load(marshaled) end |