Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
52269b66
Commit
52269b66
authored
Jun 10, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added new compress post-processor, contributed by Vasiliy Tolstov
parent
f3aed781
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
599 additions
and
68 deletions
+599
-68
post-processor/compress/LICENSE
post-processor/compress/LICENSE
+21
-0
post-processor/compress/artifact.go
post-processor/compress/artifact.go
+13
-19
post-processor/compress/benchmark.go
post-processor/compress/benchmark.go
+197
-0
post-processor/compress/post-processor.go
post-processor/compress/post-processor.go
+368
-49
No files found.
post-processor/compress/LICENSE
0 → 100644
View file @
52269b66
The MIT License (MIT)
Copyright (c) 2014 Vasiliy Tolstov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
post-processor/compress/artifact.go
View file @
52269b66
...
@@ -5,40 +5,34 @@ import (
...
@@ -5,40 +5,34 @@ import (
"os"
"os"
)
)
const
BuilderId
=
"
packer.post-processor
.compress"
const
BuilderId
=
"
vtolstov
.compress"
type
Artifact
struct
{
type
Artifact
struct
{
Path
string
builderId
string
Provider
string
dir
string
f
[]
string
}
}
func
NewArtifact
(
provider
,
path
string
)
*
Artifact
{
func
(
a
*
Artifact
)
BuilderId
()
string
{
return
&
Artifact
{
Path
:
path
,
Provider
:
provider
,
}
}
func
(
*
Artifact
)
BuilderId
()
string
{
return
BuilderId
return
BuilderId
}
}
func
(
self
*
Artifact
)
Id
()
string
{
func
(
a
*
Artifact
)
Files
()
[]
string
{
return
""
return
a
.
f
}
}
func
(
self
*
Artifact
)
Files
()
[]
string
{
func
(
*
Artifact
)
Id
()
string
{
return
[]
string
{
self
.
Path
}
return
"COMPRESS"
}
}
func
(
self
*
Artifact
)
String
()
string
{
func
(
a
*
Artifact
)
String
()
string
{
return
fmt
.
Sprintf
(
"
'%s' compressing: %s"
,
self
.
Provider
,
self
.
Path
)
return
fmt
.
Sprintf
(
"
VM compressed files in directory: %s"
,
a
.
dir
)
}
}
func
(
*
Artifact
)
State
(
name
string
)
interface
{}
{
func
(
*
Artifact
)
State
(
name
string
)
interface
{}
{
return
nil
return
nil
}
}
func
(
self
*
Artifact
)
Destroy
()
error
{
func
(
a
*
Artifact
)
Destroy
()
error
{
return
os
.
Remove
(
self
.
Path
)
return
os
.
Remove
All
(
a
.
dir
)
}
}
post-processor/compress/benchmark.go
0 → 100644
View file @
52269b66
// +build ignore
package
main
import
(
"compress/flate"
gzip
"compress/gzip"
"io"
"io/ioutil"
"fmt"
"os"
"runtime"
"testing"
bgzf
"github.com/biogo/hts/bgzf"
pgzip
"github.com/klauspost/pgzip"
lz4
"github.com/pierrec/lz4"
)
type
Compressor
struct
{
r
*
os
.
File
w
*
os
.
File
sr
int64
sw
int64
}
func
(
c
*
Compressor
)
Close
()
error
{
var
err
error
fi
,
_
:=
c
.
w
.
Stat
()
c
.
sw
=
fi
.
Size
()
if
err
=
c
.
w
.
Close
();
err
!=
nil
{
return
err
}
fi
,
_
=
c
.
r
.
Stat
()
c
.
sr
=
fi
.
Size
()
if
err
=
c
.
r
.
Close
();
err
!=
nil
{
return
err
}
return
nil
}
func
NewCompressor
(
src
,
dst
string
)
(
*
Compressor
,
error
)
{
r
,
err
:=
os
.
Open
(
src
)
if
err
!=
nil
{
return
nil
,
err
}
w
,
err
:=
os
.
Create
(
dst
)
if
err
!=
nil
{
r
.
Close
()
return
nil
,
err
}
c
:=
&
Compressor
{
r
:
r
,
w
:
w
}
return
c
,
nil
}
func
main
()
{
runtime
.
GOMAXPROCS
(
runtime
.
NumCPU
())
var
resw
testing
.
BenchmarkResult
var
resr
testing
.
BenchmarkResult
c
,
err
:=
NewCompressor
(
"/tmp/image.r"
,
"/tmp/image.w"
)
if
err
!=
nil
{
panic
(
err
)
}
resw
=
testing
.
Benchmark
(
c
.
BenchmarkGZIPWriter
)
c
.
w
.
Seek
(
0
,
0
)
resr
=
testing
.
Benchmark
(
c
.
BenchmarkGZIPReader
)
c
.
Close
()
fmt
.
Printf
(
"gzip:
\t
writer %s
\t
reader %s
\t
size %d
\n
"
,
resw
.
T
.
String
(),
resr
.
T
.
String
(),
c
.
sw
)
c
,
err
=
NewCompressor
(
"/tmp/image.r"
,
"/tmp/image.w"
)
if
err
!=
nil
{
panic
(
err
)
}
resw
=
testing
.
Benchmark
(
c
.
BenchmarkBGZFWriter
)
c
.
w
.
Seek
(
0
,
0
)
resr
=
testing
.
Benchmark
(
c
.
BenchmarkBGZFReader
)
c
.
Close
()
fmt
.
Printf
(
"bgzf:
\t
writer %s
\t
reader %s
\t
size %d
\n
"
,
resw
.
T
.
String
(),
resr
.
T
.
String
(),
c
.
sw
)
c
,
err
=
NewCompressor
(
"/tmp/image.r"
,
"/tmp/image.w"
)
if
err
!=
nil
{
panic
(
err
)
}
resw
=
testing
.
Benchmark
(
c
.
BenchmarkPGZIPWriter
)
c
.
w
.
Seek
(
0
,
0
)
resr
=
testing
.
Benchmark
(
c
.
BenchmarkPGZIPReader
)
c
.
Close
()
fmt
.
Printf
(
"pgzip:
\t
writer %s
\t
reader %s
\t
size %d
\n
"
,
resw
.
T
.
String
(),
resr
.
T
.
String
(),
c
.
sw
)
c
,
err
=
NewCompressor
(
"/tmp/image.r"
,
"/tmp/image.w"
)
if
err
!=
nil
{
panic
(
err
)
}
resw
=
testing
.
Benchmark
(
c
.
BenchmarkLZ4Writer
)
c
.
w
.
Seek
(
0
,
0
)
resr
=
testing
.
Benchmark
(
c
.
BenchmarkLZ4Reader
)
c
.
Close
()
fmt
.
Printf
(
"lz4:
\t
writer %s
\t
reader %s
\t
size %d
\n
"
,
resw
.
T
.
String
(),
resr
.
T
.
String
(),
c
.
sw
)
}
func
(
c
*
Compressor
)
BenchmarkGZIPWriter
(
b
*
testing
.
B
)
{
cw
,
_
:=
gzip
.
NewWriterLevel
(
c
.
w
,
flate
.
BestSpeed
)
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
cw
,
c
.
r
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
cw
.
Close
()
c
.
w
.
Sync
()
}
func
(
c
*
Compressor
)
BenchmarkGZIPReader
(
b
*
testing
.
B
)
{
cr
,
_
:=
gzip
.
NewReader
(
c
.
w
)
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
ioutil
.
Discard
,
cr
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
func
(
c
*
Compressor
)
BenchmarkBGZFWriter
(
b
*
testing
.
B
)
{
cw
,
_
:=
bgzf
.
NewWriterLevel
(
c
.
w
,
flate
.
BestSpeed
,
runtime
.
NumCPU
())
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
cw
,
c
.
r
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
c
.
w
.
Sync
()
}
func
(
c
*
Compressor
)
BenchmarkBGZFReader
(
b
*
testing
.
B
)
{
cr
,
_
:=
bgzf
.
NewReader
(
c
.
w
,
0
)
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
ioutil
.
Discard
,
cr
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
func
(
c
*
Compressor
)
BenchmarkPGZIPWriter
(
b
*
testing
.
B
)
{
cw
,
_
:=
pgzip
.
NewWriterLevel
(
c
.
w
,
flate
.
BestSpeed
)
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
cw
,
c
.
r
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
cw
.
Close
()
c
.
w
.
Sync
()
}
func
(
c
*
Compressor
)
BenchmarkPGZIPReader
(
b
*
testing
.
B
)
{
cr
,
_
:=
pgzip
.
NewReader
(
c
.
w
)
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
ioutil
.
Discard
,
cr
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
func
(
c
*
Compressor
)
BenchmarkLZ4Writer
(
b
*
testing
.
B
)
{
cw
:=
lz4
.
NewWriter
(
c
.
w
)
// cw.Header.HighCompression = true
cw
.
Header
.
NoChecksum
=
true
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
cw
,
c
.
r
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
cw
.
Close
()
c
.
w
.
Sync
()
}
func
(
c
*
Compressor
)
BenchmarkLZ4Reader
(
b
*
testing
.
B
)
{
cr
:=
lz4
.
NewReader
(
c
.
w
)
b
.
ResetTimer
()
_
,
err
:=
io
.
Copy
(
ioutil
.
Discard
,
cr
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}
post-processor/compress/post-processor.go
View file @
52269b66
This diff is collapsed.
Click to expand it.
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