class NVD::JSONFeeds::ZipFeedFile

Represents a `.json.zip` feed file.

Public Instance Methods

extract() click to toggle source

Extracts the feed file.

@return [JSONFeedFile]

@raise [ExtractFailed]

The `unzip` command failed or the `.json` file was not extracted.
# 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() click to toggle source

The filename of the `.json` file within the `.zip` archive.

@return [String]

# File lib/nvd/json_feeds/zip_feed_file.rb, line 21
def json_filename
  File.basename(@path,'.zip')
end
read() click to toggle source

Reads the compressed feed file.

@return [String]

@raise [ReadFailed]

The `unzip` command is not installed.
# 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