Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
B
beego
Project
Project
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
beego
Commits
ee2322e8
Commit
ee2322e8
authored
Jan 03, 2016
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add any level compress
parent
59fa2482
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
acceptencoder.go
context/acceptencoder.go
+9
-4
No files found.
context/acceptencoder.go
View file @
ee2322e8
...
...
@@ -40,9 +40,9 @@ func (n nopResetWriter) Reset(w io.Writer) {
//do nothing
}
type
encodeFunc
func
(
io
.
Writer
,
int
)
(
resetWriter
,
error
)
type
acceptEncoder
struct
{
name
string
levelEncode
func
(
int
)
resetWriter
bestSpeedPool
*
sync
.
Pool
bestCompressionPool
*
sync
.
Pool
}
...
...
@@ -52,10 +52,13 @@ func (ac acceptEncoder) encode(wr io.Writer, level int) (resetWriter, error) {
return
nopResetWriter
{
wr
},
nil
}
var
rwr
resetWriter
if
level
==
flate
.
BestSpeed
{
switch
level
{
case
flate
.
BestSpeed
:
rwr
=
ac
.
bestSpeedPool
.
Get
()
.
(
resetWriter
)
}
else
{
case
flate
.
BestCompression
:
rwr
=
ac
.
bestCompressionPool
.
Get
()
.
(
resetWriter
)
default
:
rwr
=
ac
.
levelEncode
(
level
)
}
rwr
.
Reset
(
wr
)
return
rwr
,
nil
...
...
@@ -75,8 +78,9 @@ func (ac acceptEncoder) put(wr resetWriter, level int) {
}
var
(
noneCompressEncoder
=
acceptEncoder
{
""
,
nil
,
nil
}
noneCompressEncoder
=
acceptEncoder
{
""
,
nil
,
nil
,
nil
}
gzipCompressEncoder
=
acceptEncoder
{
"gzip"
,
func
(
level
int
)
resetWriter
{
wr
,
_
:=
gzip
.
NewWriterLevel
(
nil
,
level
);
return
wr
},
&
sync
.
Pool
{
New
:
func
()
interface
{}
{
wr
,
_
:=
gzip
.
NewWriterLevel
(
nil
,
flate
.
BestSpeed
);
return
wr
},
},
...
...
@@ -90,6 +94,7 @@ var (
//The "zlib" format defined in RFC 1950 [31] in combination with
//the "deflate" compression mechanism described in RFC 1951 [29].
deflateCompressEncoder
=
acceptEncoder
{
"deflate"
,
func
(
level
int
)
resetWriter
{
wr
,
_
:=
zlib
.
NewWriterLevel
(
nil
,
level
);
return
wr
},
&
sync
.
Pool
{
New
:
func
()
interface
{}
{
wr
,
_
:=
zlib
.
NewWriterLevel
(
nil
,
flate
.
BestSpeed
);
return
wr
},
},
...
...
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