Class: NVD::JSONFeeds::GzFeedFile
- Defined in:
- lib/nvd/json_feeds/gz_feed_file.rb
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.gz
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.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/nvd/json_feeds/gz_feed_file.rb', line 44 def extract unless system('gunzip', '-q', '-k', @path) raise(ExtractFailed,"gunzip command failed") end extracted_dir = File.dirname(@path) 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 .gz
archive.
18 19 20 |
# File 'lib/nvd/json_feeds/gz_feed_file.rb', line 18 def json_filename File.basename(@path,'.gz') end |
#read ⇒ String
Reads the compressed feed file.
30 31 32 33 34 |
# File 'lib/nvd/json_feeds/gz_feed_file.rb', line 30 def read `gunzip -q -c -k #{Shellwords.escape(@path)}` rescue Errno::ENOENT raise(ReadFailed,"gunzip command is not installed") end |