Sha256: e6fb67a330a456d33810561974eeb759d66f46959bc18217b9804582921aecaa
Contents?: true
Size: 1.97 KB
Versions: 1
Compression:
Stored size: 1.97 KB
Contents
module Rambling module Trie module Serializers # Zip file serializer. Dumps/loads contents from zip files. Automatically # detects if zip file contains `.marshal` or `.yml` file class Zip # Creates a new Zip serializer. # @param [Configuration::Properties] properties the configuration # properties set up so far. def initialize properties @properties = properties end # Unzip contents from specified filepath and load in contents from # unzipped files. # @param [String] filepath the filepath to load contents from. # @return [String] all contents of the unzipped loaded file. def load filepath require 'zip' ::Zip::File.open filepath do |zip| entry = zip.entries.first entry_path = path entry.name entry.extract entry_path serializer = serializers.resolve entry.name serializer.load entry_path end end # Dumps contents and zips into a specified filepath. # @param [String] contents the contents to dump. # @param [String] filepath the filepath to dump the contents to. # @return [Numeric] number of bytes written to disk. def dump contents, filepath require 'zip' ::Zip::File.open filepath, ::Zip::File::CREATE do |zip| filename = ::File.basename filepath, '.zip' entry_path = path filename serializer = serializers.resolve filename serializer.dump contents, entry_path zip.add filename, entry_path end end private attr_reader :properties def serializers properties.serializers end def tmp_path properties.tmp_path end def path filename require 'securerandom' ::File.join tmp_path, "#{SecureRandom.uuid}-#{filename}" end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rambling-trie-1.0.3 | lib/rambling/trie/serializers/zip.rb |