Skip to content

Commit

Permalink
Add methods to read/write matrix to base64
Browse files Browse the repository at this point in the history
  • Loading branch information
bradleybuda committed Nov 1, 2011
1 parent b7d925c commit 5f7793b
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions params_matrix.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'matrix' require 'matrix'
require 'stringio'


class ParamsMatrix class ParamsMatrix
ROWS = 8 ROWS = 8
Expand All @@ -21,6 +22,18 @@ def self.write(io, matrix)
end end
end end


def self.to_base64(matrix)
io = StringIO.new
write(io, matrix)
[io.string].pack("m0")
end

def self.from_base64(str)
bytes = str.unpack("m0").first
io = StringIO.new(bytes)
read(io)
end

def self.with_binary_io(io) def self.with_binary_io(io)
io.binmode io.binmode
return yield return yield
Expand Down

0 comments on commit 5f7793b

Please sign in to comment.