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
6ad215a9
Commit
6ad215a9
authored
Sep 22, 2015
by
JessonChan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mem zip file var refactor
parent
9c17f734
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
28 deletions
+28
-28
memzipfile.go
memzipfile.go
+28
-28
No files found.
memzipfile.go
View file @
6ad215a9
...
...
@@ -29,72 +29,72 @@ import (
)
var
(
gmfim
=
make
(
map
[
string
]
*
memFileInfo
)
lock
sync
.
RWMutex
menFileInfoMap
=
make
(
map
[
string
]
*
memFileInfo
)
lock
sync
.
RWMutex
)
//
O
penMemZipFile returns MemFile object with a compressed static file.
//
o
penMemZipFile returns MemFile object with a compressed static file.
// it's used for serve static file if gzip enable.
func
openMemZipFile
(
path
string
,
zip
string
)
(
*
memFile
,
error
)
{
os
f
ile
,
e
:=
os
.
Open
(
path
)
os
F
ile
,
e
:=
os
.
Open
(
path
)
if
e
!=
nil
{
return
nil
,
e
}
defer
os
f
ile
.
Close
()
defer
os
F
ile
.
Close
()
os
fileinfo
,
e
:=
osf
ile
.
Stat
()
os
FileInfo
,
e
:=
osF
ile
.
Stat
()
if
e
!=
nil
{
return
nil
,
e
}
mod
time
:=
osfilei
nfo
.
ModTime
()
fileSize
:=
os
filei
nfo
.
Size
()
mod
Time
:=
osFileI
nfo
.
ModTime
()
fileSize
:=
os
FileI
nfo
.
Size
()
lock
.
RLock
()
cfi
,
ok
:=
gmfim
[
zip
+
":"
+
path
]
cfi
,
ok
:=
menFileInfoMap
[
zip
+
":"
+
path
]
lock
.
RUnlock
()
if
!
(
ok
&&
cfi
.
ModTime
()
==
mod
t
ime
&&
cfi
.
fileSize
==
fileSize
)
{
if
!
(
ok
&&
cfi
.
ModTime
()
==
mod
T
ime
&&
cfi
.
fileSize
==
fileSize
)
{
var
content
[]
byte
if
zip
==
"gzip"
{
var
zip
b
uf
bytes
.
Buffer
gzip
writer
,
e
:=
gzip
.
NewWriterLevel
(
&
zipb
uf
,
gzip
.
BestCompression
)
var
zip
B
uf
bytes
.
Buffer
gzip
Writer
,
e
:=
gzip
.
NewWriterLevel
(
&
zipB
uf
,
gzip
.
BestCompression
)
if
e
!=
nil
{
return
nil
,
e
}
_
,
e
=
io
.
Copy
(
gzip
writer
,
osf
ile
)
gzip
w
riter
.
Close
()
_
,
e
=
io
.
Copy
(
gzip
Writer
,
osF
ile
)
gzip
W
riter
.
Close
()
if
e
!=
nil
{
return
nil
,
e
}
content
,
e
=
ioutil
.
ReadAll
(
&
zip
b
uf
)
content
,
e
=
ioutil
.
ReadAll
(
&
zip
B
uf
)
if
e
!=
nil
{
return
nil
,
e
}
}
else
if
zip
==
"deflate"
{
var
zip
b
uf
bytes
.
Buffer
deflate
writer
,
e
:=
flate
.
NewWriter
(
&
zipb
uf
,
flate
.
BestCompression
)
var
zip
B
uf
bytes
.
Buffer
deflate
Writer
,
e
:=
flate
.
NewWriter
(
&
zipB
uf
,
flate
.
BestCompression
)
if
e
!=
nil
{
return
nil
,
e
}
_
,
e
=
io
.
Copy
(
deflate
writer
,
osf
ile
)
deflate
w
riter
.
Close
()
_
,
e
=
io
.
Copy
(
deflate
Writer
,
osF
ile
)
deflate
W
riter
.
Close
()
if
e
!=
nil
{
return
nil
,
e
}
content
,
e
=
ioutil
.
ReadAll
(
&
zip
b
uf
)
content
,
e
=
ioutil
.
ReadAll
(
&
zip
B
uf
)
if
e
!=
nil
{
return
nil
,
e
}
}
else
{
content
,
e
=
ioutil
.
ReadAll
(
os
f
ile
)
content
,
e
=
ioutil
.
ReadAll
(
os
F
ile
)
if
e
!=
nil
{
return
nil
,
e
}
}
cfi
=
&
memFileInfo
{
os
fileinfo
,
modt
ime
,
content
,
int64
(
len
(
content
)),
fileSize
}
cfi
=
&
memFileInfo
{
os
FileInfo
,
modT
ime
,
content
,
int64
(
len
(
content
)),
fileSize
}
lock
.
Lock
()
defer
lock
.
Unlock
()
gmfim
[
zip
+
":"
+
path
]
=
cfi
menFileInfoMap
[
zip
+
":"
+
path
]
=
cfi
}
return
&
memFile
{
fi
:
cfi
,
offset
:
0
},
nil
}
...
...
@@ -139,7 +139,7 @@ func (fi *memFileInfo) Sys() interface{} {
return
nil
}
//
M
emFile contains MemFileInfo and bytes offset when reading.
//
m
emFile contains MemFileInfo and bytes offset when reading.
// it implements io.Reader,io.ReadCloser and io.Seeker.
type
memFile
struct
{
fi
*
memFileInfo
...
...
@@ -198,7 +198,7 @@ func (f *memFile) Seek(offset int64, whence int) (ret int64, err error) {
return
f
.
offset
,
nil
}
//
G
etAcceptEncodingZip returns accept encoding format in http header.
//
g
etAcceptEncodingZip returns accept encoding format in http header.
// zip is first, then deflate if both accepted.
// If no accepted, return empty string.
func
getAcceptEncodingZip
(
r
*
http
.
Request
)
string
{
...
...
@@ -206,9 +206,9 @@ func getAcceptEncodingZip(r *http.Request) string {
ss
=
strings
.
ToLower
(
ss
)
if
strings
.
Contains
(
ss
,
"gzip"
)
{
return
"gzip"
}
else
if
strings
.
Contains
(
ss
,
"deflate"
)
{
}
if
strings
.
Contains
(
ss
,
"deflate"
)
{
return
"deflate"
}
else
{
return
""
}
return
""
}
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