Module: OpenURI::OpenRead

Defined in:
opal/stdlib/open-uri.rb

Overview

Mixin for HTTP and FTP URIs.

Instance Method Summary collapse

Instance Method Details

#open(*rest, &block) ⇒ Object

OpenURI::OpenRead#open provides `open' for URI::HTTP and URI::FTP.

OpenURI::OpenRead#open takes optional 3 arguments as:

OpenURI::OpenRead#open([mode [, perm]] [, options]) [{|io| ... }]

OpenURI::OpenRead#open returns an IO-like object if block is not given. Otherwise it yields the IO object and return the value of the block. The IO object is extended with OpenURI::Meta.

+mode+ and +perm+ are the same as Kernel#open.

However, +mode+ must be read mode because OpenURI::OpenRead#open doesn't support write mode (yet). Also +perm+ is ignored because it is meaningful only for file creation.



336
337
338
# File 'opal/stdlib/open-uri.rb', line 336

def open(*rest, &block)
  OpenURI.open_uri(self, *rest, &block)
end

#read(options = {}) ⇒ Object

OpenURI::OpenRead#read([options]) reads a content referenced by self and returns the content as string. The string is extended with OpenURI::Meta. The argument +options+ is same as OpenURI::OpenRead#open.



344
345
346
347
348
349
350
# File 'opal/stdlib/open-uri.rb', line 344

def read(options={})
  self.open(options) {|f|
    str = f.read
    Meta.init str, f
    str
  }
end