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
214030fa
Commit
214030fa
authored
Nov 12, 2015
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bytes reader replace string reader
parent
f8db8ae9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
12 deletions
+7
-12
acceptencoder.go
context/acceptencoder.go
+5
-10
staticfile.go
staticfile.go
+2
-2
No files found.
context/acceptencoder.go
View file @
214030fa
...
...
@@ -15,6 +15,7 @@
package
context
import
(
"bytes"
"compress/flate"
"compress/gzip"
"io"
...
...
@@ -22,30 +23,24 @@ import (
"os"
"strconv"
"strings"
"io/ioutil"
)
// WriteFile reads from file and writes to writer by the specific encoding(gzip/deflate)
func
WriteFile
(
encoding
string
,
writer
io
.
Writer
,
file
*
os
.
File
)
(
bool
,
string
,
error
)
{
content
,
err
:=
ioutil
.
ReadAll
(
file
)
if
err
!=
nil
{
return
false
,
""
,
err
}
return
writeLevel
(
encoding
,
writer
,
content
,
flate
.
BestCompression
)
return
writeLevel
(
encoding
,
writer
,
file
,
flate
.
BestCompression
)
}
// WriteBody reads writes content to writer by the specific encoding(gzip/deflate)
func
WriteBody
(
encoding
string
,
writer
io
.
Writer
,
content
[]
byte
)
(
bool
,
string
,
error
)
{
return
writeLevel
(
encoding
,
writer
,
content
,
flate
.
BestSpeed
)
return
writeLevel
(
encoding
,
writer
,
bytes
.
NewReader
(
content
)
,
flate
.
BestSpeed
)
}
// writeLevel reads from reader,writes to writer by specific encoding and compress level
// the compress level is defined by deflate package
func
writeLevel
(
encoding
string
,
writer
io
.
Writer
,
content
[]
byte
,
level
int
)
(
bool
,
string
,
error
)
{
func
writeLevel
(
encoding
string
,
writer
io
.
Writer
,
reader
io
.
Reader
,
level
int
)
(
bool
,
string
,
error
)
{
var
outputWriter
io
.
Writer
var
err
error
if
cf
,
ok
:=
encoderMap
[
encoding
];
ok
{
...
...
@@ -57,7 +52,7 @@ func writeLevel(encoding string, writer io.Writer, content []byte, level int) (b
if
err
!=
nil
{
return
false
,
""
,
err
}
outputWriter
.
Write
(
content
)
io
.
Copy
(
outputWriter
,
reader
)
switch
outputWriter
.
(
type
)
{
case
io
.
WriteCloser
:
outputWriter
.
(
io
.
WriteCloser
)
.
Close
()
...
...
staticfile.go
View file @
214030fa
...
...
@@ -87,7 +87,7 @@ func serverStaticRouter(ctx *context.Context) {
}
type
serveContentHolder
struct
{
*
string
s
.
Reader
*
byte
s
.
Reader
modTime
time
.
Time
size
int64
encoding
string
...
...
@@ -120,7 +120,7 @@ func openFile(filePath string, fi os.FileInfo, acceptEncoding string) (bool, str
if
err
!=
nil
{
return
false
,
""
,
nil
,
err
}
mapFile
=
&
serveContentHolder
{
Reader
:
strings
.
NewReader
(
string
(
bufferWriter
.
Bytes
()
)),
modTime
:
fi
.
ModTime
(),
size
:
int64
(
bufferWriter
.
Len
()),
encoding
:
n
}
mapFile
=
&
serveContentHolder
{
Reader
:
bytes
.
NewReader
(
bufferWriter
.
Bytes
(
)),
modTime
:
fi
.
ModTime
(),
size
:
int64
(
bufferWriter
.
Len
()),
encoding
:
n
}
staticFileMap
[
mapKey
]
=
mapFile
}
...
...
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