Top Level Namespace

Defined Under Namespace

Modules: Pluto, PlutoTasks

Instance Method Summary collapse

Instance Method Details

#fixme_fetcher_read_utf8!(src) ⇒ Object

todo/fix: use/find better name? - e.g. Fetcher.read_utf8!() move out of global ns etc.

e.g. use Fetch.read_utf8!()  e.g. throws exception on error
                read_blob!()


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/pluto/tasks.rb', line 19

def fixme_fetcher_read_utf8!( src )
  worker = Fetcher::Worker.new
  res = worker.get_response( src )
  if res.code != '200'
    puts "sorry; failed to fetch >#{src} - HTTP #{res.code} - #{res.message}"
    exit 1
  end

  ###
  # Note: Net::HTTP will NOT set encoding UTF-8 etc.
  #  will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here
  #  thus, set/force encoding to utf-8
  txt = res.body.to_s
  txt = txt.force_encoding( Encoding::UTF_8 )
  txt
end