Class: NVD::JSONFeeds::GzFeedFile

Inherits:
FeedFile
  • Object
show all
Defined in:
lib/nvd/json_feeds/gz_feed_file.rb

Instance Attribute Summary

Attributes inherited from FeedFile

#path

Instance Method Summary collapse

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

#extractJSONFeedFile

Extracts the feed file.

Returns:

Raises:

  • (ExtractFailed)

    The gunzip command failed or did the .json file was not extracted.



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_filenameString

The filename of the .json file within the .gz archive.

Returns:

  • (String)


18
19
20
# File 'lib/nvd/json_feeds/gz_feed_file.rb', line 18

def json_filename
  File.basename(@path,'.gz')
end

#readString

Reads the compressed feed file.

Returns:

  • (String)

Raises:

  • (ReadFailed)

    The gunzip command is not installed.



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