Skip to content

Instantly share code, notes, and snippets.

@mrhead
Created January 16, 2014 13:14
Show Gist options
  • Save mrhead/8454815 to your computer and use it in GitHub Desktop.
Save mrhead/8454815 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
class Splitter
SEPARATOR = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00DICM\x02\x00"
attr_reader :file_in_string
def initialize(file)
@file_in_string = File.binread(file)
end
def split_to_files
file_parts.each_with_index do |file_part, index|
f = File.new("file_#{index}", 'w')
file_content = SEPARATOR + file_part
f.write(file_content)
f.close
end
end
def file_parts
file_in_string.split(SEPARATOR)
end
end
if ARGV.size == 1
Splitter.new(ARGV[0]).split_to_files
else
puts "Usage: ./splitter.rb <file>"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment