Class: Microsandbox::FsWriteSink

Inherits:
Object
  • Object
show all
Defined in:
lib/microsandbox/fs.rb

Overview

A streaming writer to a guest file, from Microsandbox::FS#write_stream.

Instance Method Summary collapse

Constructor Details

#initialize(native) ⇒ FsWriteSink

Returns a new instance of FsWriteSink.



233
234
235
# File 'lib/microsandbox/fs.rb', line 233

def initialize(native)
  @native = native
end

Instance Method Details

#closenil

Flush and close the sink. Idempotent.

Returns:

  • (nil)


249
250
251
252
# File 'lib/microsandbox/fs.rb', line 249

def close
  @native.close
  nil
end

#write(data) ⇒ self

Write a chunk of bytes.

Parameters:

  • data (String)

    raw bytes (binary-safe)

Returns:

  • (self)

Raises:

  • (TypeError)

    if data is not a String



241
242
243
244
245
# File 'lib/microsandbox/fs.rb', line 241

def write(data)
  bytes = Microsandbox.coerce_write_bytes(data)
  @native.write(bytes)
  self
end