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.



238
239
240
# File 'lib/microsandbox/fs.rb', line 238

def initialize(native)
  @native = native
end

Instance Method Details

#closenil

Flush and close the sink. Idempotent.

Returns:

  • (nil)


254
255
256
257
# File 'lib/microsandbox/fs.rb', line 254

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



246
247
248
249
250
# File 'lib/microsandbox/fs.rb', line 246

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