Skip to content

Add file format adapter for zip

Brian Williams requested to merge bwill/add-zip-stream-adapter into master

What does this MR do and why?

Describe in detail what your merge request does and why.

Relates to: #369472 (closed)

This adds a file format adapter which allows us to read files stored in a zip archive on the backend using Artifactable#each_blob. This is currently used in various places in order to process reports from CI jobs. This new adapter is being added to support CycloneDX reports (!91510 (merged)), which are stored as a zip.

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

Create a test archive:

mkdir directory
echo 'file-1 content' > directory/file-1
echo 'file-2 content' > directory/file-2
zip with_directory directory/*

Start the rails console:

bundle exec rails c

Run this ruby code:

stream = File.open(Rails.root.join('with_directory.zip'), 'rb')
Gitlab::Ci::Build::Artifacts::Adapters::ZipStream.new(stream).each_blob do |blob|
  puts blob
end
stream.close

expected output:

file-1 content
file-2 content

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Brian Williams

Merge request reports

Loading