Class String
In: lib/coderay/scanner.rb
lib/coderay/helpers/gzip_simple.rb
Parent: Object

String extensions to use the GZip module.

The methods gzip and gunzip provide an even more simple interface to the ZLib:

  # create a big string
  x = 'a' * 1000

  # zip it
  x_gz = x.gzip

  # test the result
  puts 'Zipped %d bytes to %d bytes.' % [x.size, x_gz.size]
  #-> Zipped 1000 bytes to 19 bytes.

  # unzipping works
  p x_gz.gunzip == x  #-> true

Methods

gunzip   gunzip!   gzip   gzip!   to_unix  

Public Instance methods

Returns the string, unzipped. See GZip.gunzip

[Source]

    # File lib/coderay/helpers/gzip_simple.rb, line 70
70:   def gunzip
71:     GZip.gunzip self
72:   end

Replaces the string with its unzipped value. See GZip.gunzip

[Source]

    # File lib/coderay/helpers/gzip_simple.rb, line 75
75:   def gunzip!
76:     replace gunzip
77:   end

Returns the string, zipped. level is the gzip compression level, see GZip.gzip.

[Source]

    # File lib/coderay/helpers/gzip_simple.rb, line 81
81:   def gzip level = GZip::DEFAULT_GZIP_LEVEL
82:     GZip.gzip self, level
83:   end

Replaces the string with its zipped value. See GZip.gzip.

[Source]

    # File lib/coderay/helpers/gzip_simple.rb, line 86
86:   def gzip!(*args)
87:     replace gzip(*args)
88:   end

I love this hack. It seems to silence all dos/unix/mac newline problems.

[Source]

     # File lib/coderay/scanner.rb, line 300
300:   def to_unix
301:     if index ?\r
302:       gsub(/\r\n?/, "\n")
303:     else
304:       self
305:     end
306:   end

[Validate]