Global Cleanup

This project was sleeping for too long. Too many parts are not clean
at all. So, here some cleanup:

 - add more test unit

 - clean msdos date/time format for zip

 - add crc32

 - add version support

 - rewrite notes

 - rewrite the whole interface from scratch.

 - update github actions

 - update license (MIT)

 - create dotzip application

 - update notes regarding data-structure used

 - fix date and time ms-dos format (issue with endianess)

 - fix local file header encoding

 - update documentation

 - update with new extra fields and third party support

 - add extended timestamp third party support

 - add unix info new third party support
This commit is contained in:
niamtokik
2021-12-28 10:11:39 +00:00
parent 93b1dc7c38
commit 1e90eaaaf3
50 changed files with 2088 additions and 337 deletions

View File

@@ -0,0 +1,13 @@
defmodule Dotzip.Crc32_test do
use ExUnit.Case, async: true
test "crc32 on bitstring" do
{:ok, <<161, 7>>} = Dotzip.Crc32.raw("a\n")
{:ok, <<137, 193>>} = Dotzip.Crc32.raw("file\n")
end
test "crc32 on file" do
{:ok, "B5"} = Dotzip.Crc32.file("test/fixtures/a.zip")
end
end

View File

@@ -0,0 +1,4 @@
defmodule Dotzip.DateTest do
use ExUnit.Case, async: true
doctest Dotzip.Date
end

View File

@@ -0,0 +1,43 @@
defmodule Dotzip.DecodeTest do
use ExUnit.Case, async: true
test "decode a simple archive with one file" do
file = "test/fixtures/a.zip"
_decoded = [
%{
:type => :file,
:name => "a.txt",
:crc => <<0xdd, 0xea, 0xa1, 0x07>>,
:offset => 0,
:origin => "Unix",
:time => <<>>,
:date => <<>>,
:version => "3.0",
:compression => :none,
:encryption => :none,
:extended_local_header => false,
:compressed_size => 2,
:uncompressed_size => 2,
:filename_length => 5,
:extra_field_length => 24,
:comment_length => 0,
:method => :stored,
:command => :none,
:extra_field => %{
:unix => %{
}
},
:content => "a\n"
}
]
{:ok, _content} = File.read(file)
:ok
end
# @file "test/fixtures/directory.zip"
# test "decode a simple archive with 2 files and a directory" do
# {:ok, _content} = File.read(@file)
# end
end

View File

@@ -0,0 +1,4 @@
defmodule Dotzip.ExtraField.Os2Test do
use ExUnit.Case, async: true
end

View File

@@ -1,17 +1,19 @@
defmodule Dotzip.ExtraField.UnixTest do
use ExUnit.Case, async: true
doctest Dotzip.ExtraField.Unix
test "decode an empty Unix field" do
struct = %{atime: 0, gid: 0, mtime: 0, uid: 0, tsize: 12}
{:ok, struct, data} = Dotzip.ExtraField.Unix.encode(struct)
{:ok, decoded_struct, decoded_data} = Dotzip.ExtraField.Unix.decode(data)
assert struct == decoded_struct
end
# test "decode an empty Unix field" do
# struct = %{atime: 0, gid: 0, mtime: 0, uid: 0, tsize: 12}
# {:ok, struct, data} = Dotzip.ExtraField.Unix.encode(struct)
# {:ok, decoded_struct, _decoded_data} = Dotzip.ExtraField.Unix.decode(data)
# assert struct == decoded_struct
# end
# test "encode an empty Unix field" do
# data = <<0, 13, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>
# {:ok, decoded_struct, _} = Dotzip.ExtraField.Unix.decode(data)
# {:ok, struct, _encoded_data} = Dotzip.ExtraField.Unix.encode(decoded_struct)
# assert struct == decoded_struct
# end
test "encode an empty Unix field" do
data = <<0, 13, 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0>>
{:ok, decoded_struct, _} = Dotzip.ExtraField.Unix.decode(data)
{:ok, struct, encoded_data} = Dotzip.ExtraField.Unix.encode(decoded_struct)
assert struct == decoded_struct
end
end

View File

@@ -0,0 +1,9 @@
defmodule Dotzip.LocalFileHeaderTest do
use ExUnit.Case, async: true
test "decode simple craft local file header" do
local_file_header= <<>>
Dotzip.LocalFileheader.decode(local_file_header)
end
end

View File

@@ -0,0 +1,4 @@
defmodule Dotzip.ThirdParty.ExtendedTimestampTest do
use ExUnit.Case, async: true
doctest Dotzip.ThirdParty.ExtendedTimestamp
end

View File

@@ -0,0 +1,4 @@
defmodule Dotzip.ThirdParty.InfoZipUnixNewTest do
use ExUnit.Case, async: true
doctest Dotzip.ThirdParty.InfoZipUnixNew
end

View File

@@ -0,0 +1,4 @@
defmodule Dotzip.TimeTest do
use ExUnit.Case, async: true
doctest Dotzip.Time
end

View File

@@ -1,8 +1,4 @@
defmodule DotzipTest do
use ExUnit.Case
doctest Dotzip
test "local file header" do
assert :world == :world
end
end

BIN
test/fixtures/a.zip vendored Normal file

Binary file not shown.

BIN
test/fixtures/directory.zip vendored Normal file

Binary file not shown.

1
test/fixtures/directory/file vendored Normal file
View File

@@ -0,0 +1 @@
file

1
test/fixtures/file vendored Normal file
View File

@@ -0,0 +1 @@
file