class GPhoto2::CameraFile

Constants

PREVIEW_FILENAME

The preview data is assumed to be a jpg.

Attributes

folder[R]

@return [String]

name[R]

@return [String]

Public Class Methods

new(camera, folder = nil, name = nil) click to toggle source

@param [GPhoto2::Camera] camera @param [String] folder @param [String] name

# File lib/gphoto2/camera_file.rb, line 18
def initialize(camera, folder = nil, name = nil)
  @camera = camera
  @folder, @name = folder, name
  new
end

Public Instance Methods

data() click to toggle source

@return [String]

# File lib/gphoto2/camera_file.rb, line 41
def data
  data_and_size.first
end
delete() click to toggle source

@return [void]

# File lib/gphoto2/camera_file.rb, line 36
def delete
  @camera.delete(self)
end
info() click to toggle source

@return [GPhoto2::CameraFileInfo, nil]

# File lib/gphoto2/camera_file.rb, line 51
def info
  preview? ? nil : get_info
end
preview?() click to toggle source

@return [Boolean]

# File lib/gphoto2/camera_file.rb, line 25
def preview?
  @folder.nil? && @name.nil?
end
save(pathname = default_filename) click to toggle source

@param [String] pathname @return [Integer] the number of bytes written

# File lib/gphoto2/camera_file.rb, line 31
def save(pathname = default_filename)
  File.binwrite(pathname, data)
end
size() click to toggle source

@return [Integer]

# File lib/gphoto2/camera_file.rb, line 46
def size
  data_and_size.last
end

Private Instance Methods

data_and_size() click to toggle source
# File lib/gphoto2/camera_file.rb, line 57
def data_and_size
  @data_and_size ||= begin
    @camera.file(self) unless preview?
    get_data_and_size
  end
end
default_filename() click to toggle source
# File lib/gphoto2/camera_file.rb, line 64
def default_filename
  preview? ? PREVIEW_FILENAME : @name
end
get_data_and_size() click to toggle source
# File lib/gphoto2/camera_file.rb, line 75
def get_data_and_size
  data_ptr = FFI::MemoryPointer.new(:pointer)
  size_ptr = FFI::MemoryPointer.new(:ulong)

  rc = gp_file_get_data_and_size(ptr, data_ptr, size_ptr)
  GPhoto2.check!(rc)

  size = size_ptr.read_ulong
  data = data_ptr.read_pointer.read_bytes(size)

  [data, size]
end
get_info() click to toggle source
# File lib/gphoto2/camera_file.rb, line 88
def get_info
  info = FFI::GPhoto2::CameraFileInfo.new

  rc = gp_camera_file_get_info(@camera.ptr,
                               @folder,
                               @name,
                               info,
                               @camera.context.ptr)
  GPhoto2.check!(rc)

  FileCameraFileInfo.new(info[:file])
end
new() click to toggle source
# File lib/gphoto2/camera_file.rb, line 68
def new
  ptr = FFI::MemoryPointer.new(:pointer)
  rc = gp_file_new(ptr)
  GPhoto2.check!(rc)
  @ptr = FFI::GPhoto2::CameraFile.new(ptr.read_pointer)
end