Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
4bc1a30f
Commit
4bc1a30f
authored
Jun 10, 2012
by
Michael Schubert
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
util: add git__compress()
parent
21e0d297
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
0 deletions
+69
-0
src/compress.c
+53
-0
src/compress.h
+16
-0
No files found.
src/compress.c
0 → 100644
View file @
4bc1a30f
/*
* Copyright (C) 2009-2012 the libgit2 contributors
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "compress.h"
#include <zlib.h>
#define BUFFER_SIZE (1024 * 1024)
int
git__compress
(
git_buf
*
buf
,
const
void
*
buff
,
size_t
len
)
{
z_stream
zs
;
char
*
zb
;
size_t
have
;
memset
(
&
zs
,
0
,
sizeof
(
zs
));
if
(
deflateInit
(
&
zs
,
Z_DEFAULT_COMPRESSION
)
!=
Z_OK
)
return
-
1
;
zb
=
git__malloc
(
BUFFER_SIZE
);
GITERR_CHECK_ALLOC
(
zb
);
zs
.
next_in
=
(
void
*
)
buff
;
zs
.
avail_in
=
(
uInt
)
len
;
do
{
zs
.
next_out
=
(
unsigned
char
*
)
zb
;
zs
.
avail_out
=
BUFFER_SIZE
;
if
(
deflate
(
&
zs
,
Z_FINISH
)
==
Z_STREAM_ERROR
)
{
git__free
(
zb
);
return
-
1
;
}
have
=
BUFFER_SIZE
-
(
size_t
)
zs
.
avail_out
;
if
(
git_buf_put
(
buf
,
zb
,
have
)
<
0
)
{
git__free
(
zb
);
return
-
1
;
}
}
while
(
zs
.
avail_out
==
0
);
assert
(
zs
.
avail_in
==
0
);
deflateEnd
(
&
zs
);
git__free
(
zb
);
return
0
;
}
src/compress.h
0 → 100644
View file @
4bc1a30f
/*
* Copyright (C) 2009-2012 the libgit2 contributors
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#ifndef INCLUDE_compress_h__
#define INCLUDE_compress_h__
#include "common.h"
#include "buffer.h"
int
git__compress
(
git_buf
*
buf
,
const
void
*
buff
,
size_t
len
);
#endif
/* INCLUDE_compress_h__ */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment