Class: NVD::JSONFeeds::ZipFeedFile
- Defined in:
- lib/nvd/json_feeds/zip_feed_file.rb
Overview
Represents a .json.zip
feed file.
Instance Attribute Summary
Attributes inherited from FeedFile
Instance Method Summary collapse
-
#extract ⇒ JSONFeedFile
Extracts the feed file.
-
#json_filename ⇒ String
The filename of the
.json
file within the.zip
archive. -
#read ⇒ String
Reads the compressed feed file.
Methods inherited from FeedFile
#initialize, #inspect, #json, parse, #parse, #sha256, #to_s
Constructor Details
This class inherits a constructor from NVD::JSONFeeds::FeedFile
Instance Method Details
#extract ⇒ JSONFeedFile
Extracts the feed file.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/nvd/json_feeds/zip_feed_file.rb', line 47 def extract extracted_dir = File.dirname(@path) unless system('unzip', '-qq', '-d', extracted_dir, @path, json_filename) raise(ExtractFailed,"unzip command failed") end extracted_path = File.join(extracted_dir,json_filename) unless File.file?(extracted_path) raise(ExtractFailed,"extraction failed: #{@path.inspect}") end return JSONFeedFile.new(extracted_path) end |
#json_filename ⇒ String
The filename of the .json
file within the .zip
archive.
21 22 23 |
# File 'lib/nvd/json_feeds/zip_feed_file.rb', line 21 def json_filename File.basename(@path,'.zip') end |
#read ⇒ String
Reads the compressed feed file.
33 34 35 36 37 |
# File 'lib/nvd/json_feeds/zip_feed_file.rb', line 33 def read `unzip -qq -p #{Shellwords.escape(@path)} #{Shellwords.escape(json_filename)}` rescue Errno::ENOENT raise(ReadFailed,"unzip command is not installed") end |