Class: Transfer

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

Overview

The Transfer class manages the importing and exporting of Hitsuji files. This functionality is normally accessed through Hitsuji#import and Hitsuji#export. Transfer.export also does not work independently, and must be used through the Hitsuji#export function.

Class Method Summary collapse

Class Method Details

.export(directory, struct, metadata) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/transfer.rb', line 8

def self.export(directory, struct, )
  throw 'err' unless directory.end_with?('.hitsuji')
  File.open(directory, 'w') do |file|
    raw_data = { struct: struct, metadata:  }
    serialized_data = [Marshal.dump(raw_data)].pack('u')
    file.write serialized_data
  end
end

.import(directory) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/transfer.rb', line 17

def self.import(directory)
  throw 'err' unless directory.end_with?('.hitsuji')
  File.open(directory, 'r') do |file|
    serialized_data = file.read.unpack('u')
    raw_data = Marshal.load(serialized_data.first)
    return raw_data[:struct], raw_data[:metadata]
  end
end