Hey all
I am trying to create a script which has two main functions:
This is what I have come up with:
The compile method seems to work properly: I insert a .txt file which contains my text in the directory, and the scripts creates a serialized .rxdata file of that. But when I use the extract method (from .rxdata to .txt) it throws me an error which makes me think I am making some kind of mistake somewhere:
I would appreciate it if someone would help me out here.
Thanks in advance!
I am trying to create a script which has two main functions:
- take a .txt file and convert it into an .rxdata file (using Marshal.dump),
- take an .rxdata file and convert it into a (readable) .txt file.
This is what I have come up with:
- module Rxdata
- def self.compile(file)
- @data=[]
- File.open("Data/#{file}.txt",'rb') do |file|
- file.each_line { |line| @data << line.chomp }
- end
- p @data
- dest_file="Data/#{file}.rxdata"
- temp = File.open(dest_file, "w+")
- Marshal.dump(@data, temp)
- temp.close
- end
- def self.extract(file)
- @data=Marshal.load("Data/#{file}.rxdata")
- dest_file="Data/#{file}.txt"
- File.new(dest_file)
- temp=File.open(dest_file,"w+")
- for i in @data.size
- temp.write(@data[i])
- end
- temp.close
- end
- end
Expand to see the code.
The compile method seems to work properly: I insert a .txt file which contains my text in the directory, and the scripts creates a serialized .rxdata file of that. But when I use the extract method (from .rxdata to .txt) it throws me an error which makes me think I am making some kind of mistake somewhere:
error wrote:
Script 'rxdata' line 17: TypeError occured.
incompatible marshal file format (can't be read)
format version 4.8 required; 68.97 given
incompatible marshal file format (can't be read)
format version 4.8 required; 68.97 given
I would appreciate it if someone would help me out here.
Thanks in advance!