Class: GCSStreamUpload

Inherits:
Object
  • Object
show all
Defined in:
lib/gcs_stream_upload/version.rb,
lib/gcs_stream_upload.rb

Constant Summary collapse

VERSION =
"0.1.0"

Instance Method Summary collapse

Constructor Details

#initialize(bucket) ⇒ GCSStreamUpload

Returns a new instance of GCSStreamUpload.



29
30
31
# File 'lib/gcs_stream_upload.rb', line 29

def initialize(bucket)
  @bucket = bucket
end

Instance Method Details

#upload(*args) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/gcs_stream_upload.rb', line 33

def upload(*args)
  read_pipe, write_pipe = IO.pipe
  def read_pipe.pos
    0
  end
  def read_pipe.pos=(value)
  end
  thread = Thread.start do
    yield(write_pipe)
  rescue StandardError => e
    e
  ensure
    write_pipe.close_write
  end
  @bucket.create_file(read_pipe, *args)
  result = thread.value
  raise result if result.is_a?(StandardError)
end