Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:24
erlang
5071-Added-zip-zip_get_crc32-2-to-CRC32-sum-of-...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 5071-Added-zip-zip_get_crc32-2-to-CRC32-sum-of-open-zip-f.patch of Package erlang
From 99ce627cd7de26b0d21b595bb79eedae8a57cdb1 Mon Sep 17 00:00:00 2001 From: Dominic Letz <dominic@diode.io> Date: Fri, 17 Jun 2022 13:09:20 +0200 Subject: [PATCH] Added `zip:zip_get_crc32/2` to CRC32 sum of open zip files --- lib/stdlib/doc/src/zip.xml | 8 ++++++++ lib/stdlib/src/zip.erl | 21 ++++++++++++++++++++- lib/stdlib/test/zip_SUITE.erl | 2 ++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/stdlib/doc/src/zip.xml b/lib/stdlib/doc/src/zip.xml index a056621ca1..03c28f5d3c 100644 --- a/lib/stdlib/doc/src/zip.xml +++ b/lib/stdlib/doc/src/zip.xml @@ -506,6 +506,14 @@ </desc> </func> + <func> + <name name="zip_get_crc32" arity="2" since="OTP 25.1"/> + <fsummary>Extracts a crc32 checksum from an open archive.</fsummary> + <desc> + <p>Extracts one crc32 checksum from an open archive.</p> + </desc> + </func> + <func> <name name="zip_list_dir" arity="1" since=""/> <fsummary>Return a table of files in open zip archive.</fsummary> diff --git a/lib/stdlib/src/zip.erl b/lib/stdlib/src/zip.erl index c59398a84e..0809dbb492 100644 --- a/lib/stdlib/src/zip.erl +++ b/lib/stdlib/src/zip.erl @@ -35,7 +35,7 @@ %% zip server -export([zip_open/1, zip_open/2, - zip_get/1, zip_get/2, + zip_get/1, zip_get/2, zip_get_crc32/2, zip_t/1, zip_tt/1, zip_list_dir/1, zip_list_dir/2, zip_close/1]). @@ -267,6 +267,13 @@ do_openzip_get(#openzip{files = Files, in = In0, input = Input, do_openzip_get(_) -> throw(einval). +%% retrieve the crc32 checksum from an open archive +openzip_get_crc32(FileName, #openzip{files = Files}) -> + case file_name_search(FileName, Files) of + {_,#zip_file_extra{crc32=CRC}} -> {ok, CRC}; + _ -> throw(file_not_found) + end. + %% retrieve a file from an open archive openzip_get(FileName, OpenZip) -> case ?CATCH(do_openzip_get(FileName, OpenZip)) of @@ -1165,6 +1172,9 @@ server_loop(Parent, OpenZip) -> {From, {get, FileName}} -> From ! {self(), openzip_get(FileName, OpenZip)}, server_loop(Parent, OpenZip); + {From, {get_crc32, FileName}} -> + From ! {self(), openzip_get_crc32(FileName, OpenZip)}, + server_loop(Parent, OpenZip); {From, list_dir} -> From ! {self(), openzip_list_dir(OpenZip)}, server_loop(Parent, OpenZip); @@ -1223,6 +1233,15 @@ zip_close(Pid) when is_pid(Pid) -> zip_get(FileName, Pid) when is_pid(Pid) -> request(self(), Pid, {get, FileName}). +-spec(zip_get_crc32(FileName, ZipHandle) -> {ok, CRC} | {error, Reason} when + FileName :: file:name(), + ZipHandle :: handle(), + CRC :: non_neg_integer(), + Reason :: term()). + +zip_get_crc32(FileName, Pid) when is_pid(Pid) -> + request(self(), Pid, {get_crc32, FileName}). + -spec(zip_list_dir(ZipHandle) -> {ok, Result} | {error, Reason} when Result :: [zip_comment() | zip_file()], ZipHandle :: handle(), diff --git a/lib/stdlib/test/zip_SUITE.erl b/lib/stdlib/test/zip_SUITE.erl index 1709acc523..f44095a732 100644 --- a/lib/stdlib/test/zip_SUITE.erl +++ b/lib/stdlib/test/zip_SUITE.erl @@ -280,6 +280,8 @@ zip_api(Config) when is_list(Config) -> Name1 = hd(Names), {ok, Data1} = file:read_file(Name1), {ok, {Name1, Data1}} = zip:zip_get(Name1, ZipSrv), + Data1Crc = erlang:crc32(Data1), + {ok, Data1Crc} = zip:zip_get_crc32(Name1, ZipSrv), %% Get all files FilesDatas = lists:map(fun(Name) -> {ok, B} = file:read_file(Name), -- 2.35.3
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor