Skip to content

Commit

Permalink
Merge pull request #30 from mamantoha/zip64
Browse files Browse the repository at this point in the history
Zip64
  • Loading branch information
mamantoha authored Sep 12, 2020
2 parents 530ad1b + 13892c3 commit ad9c115
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .ameba.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Metrics/CyclomaticComplexity:
Description: Disallows methods with a cyclomatic complexity higher than `MaxComplexity`
MaxComplexity: 10
Excluded:
- src/zipstream/http/server/handlers/static_file_handler.cr
Enabled: true
Severity: Convention
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ OPTIONS
-f FORMAT, --format=FORMAT the format of output archive, zip, tar or tgz. Only for CLI mode. (default: `zip`)
-o FILENAME, --output=FILENAME the output file name without extension. Only for CLI mode. (default: `download`)
-e PATH, --endpoint=PATH the URL path to the resource. Only for CLI mode. (default: ``)
-j, --junk-parent stream the content of an archive without including the parent directory
-h, --hidden match hidden files and folders
--user=user the username user for file retrieval
--password=password the password password for file retrieval
-V, --version print program version
Expand Down
4 changes: 4 additions & 0 deletions shard.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
version: 2.0
shards:
cr_zip_tricks:
git: https://github.com/mamantoha/cr_zip_tricks.git
version: 0.2.0+git.commit.e524228904e94f144bc4b240d5e0e0b2502cdb2c

crystar:
git: https://github.com/naqvis/crystar.git
version: 0.1.8
Expand Down
3 changes: 3 additions & 0 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ dependencies:
crystar:
github: naqvis/crystar
version: ">= 0.1.8"
cr_zip_tricks:
github: mamantoha/cr_zip_tricks
branch: crystal/0.35.1

targets:
zipstream:
Expand Down
2 changes: 1 addition & 1 deletion src/zipstream.cr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require "compress/zip"
require "compress/gzip"
require "http/server"
require "mime"
require "option_parser"
require "crystar"
require "cr_zip_tricks"

require "./zipstream/**"

Expand Down
4 changes: 4 additions & 0 deletions src/zipstream/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ module Zipstream
config.junk = true
end

parser.on("-h", "--hidden", "match hidden files and folders") do
config.hidden = true
end

parser.on("--user=user", "the username user for file retrieval") do |name|
config.user = name
end
Expand Down
1 change: 1 addition & 0 deletions src/zipstream/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Zipstream
property password : String? = nil
property prefix : String? = nil
property junk : Bool = false
property hidden : Bool = false

def initialize
@host = "0.0.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/zipstream/http/server/handlers/tar_helper.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Zipstream
module TarHelper
def tar_directory!(path : String, io)
Crystar::Writer.open(io) do |tar|
Dir[File.join(path, "**/*")].each do |entry|
Dir.glob(File.join(path, "**/*"), match_hidden: config.hidden).each do |entry|
next unless File.readable?(entry)

relative_path = [config.prefix, entry.sub(path, "").lstrip("/")].compact.join("/")
Expand Down
16 changes: 10 additions & 6 deletions src/zipstream/http/server/handlers/zip_handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -35,24 +35,28 @@ module Zipstream
end

private def zip_directory!(path : String, io : IO)
Compress::Zip::Writer.open(io) do |zip|
Dir[File.join(path, "**/*")].each do |entry|
ZipTricks::Streamer.archive(io) do |zip|
Dir.glob(File.join(path, "**/*"), match_hidden: config.hidden).each do |entry|
next unless File.readable?(entry)

relative_path = [config.prefix, entry.sub(path, "").lstrip("/")].compact.join("/")

if File.directory?(entry)
zip.add_dir(relative_path)
zip.add_stored("#{relative_path}/") { }
else
zip.add(relative_path, File.open(entry))
zip.add_deflated(relative_path) do |sink|
sink << File.read(entry)
end
end
end
end
end

private def zip_file!(file : String, io : IO)
Compress::Zip::Writer.open(io) do |zip|
zip.add("/#{File.basename(file)}", File.read(file))
ZipTricks::Streamer.archive(io) do |zip|
zip.add_deflated("/#{File.basename(file)}") do |sink|
sink << File.read(file)
end
end
end
end
Expand Down

0 comments on commit ad9c115

Please sign in to comment.