Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
0fac705e
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
0fac705e
编写于
4月 09, 2018
作者:
F
Felix Lange
提交者:
GitHub
4月 09, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
compression/rle: delete RLE compression (#16468)
上级
315b9b18
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
2 addition
and
170 deletion
+2
-170
compression/rle/read_write.go
compression/rle/read_write.go
+0
-101
compression/rle/read_write_test.go
compression/rle/read_write_test.go
+0
-50
ethdb/database.go
ethdb/database.go
+0
-6
swarm/storage/database.go
swarm/storage/database.go
+2
-13
未找到文件。
compression/rle/read_write.go
已删除
100644 → 0
浏览文件 @
315b9b18
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package rle implements the run-length encoding used for Ethereum data.
package
rle
import
(
"bytes"
"errors"
"github.com/ethereum/go-ethereum/crypto"
)
const
(
token
byte
=
0xfe
emptyShaToken
=
0xfd
emptyListShaToken
=
0xfe
tokenToken
=
0xff
)
var
empty
=
crypto
.
Keccak256
([]
byte
(
""
))
var
emptyList
=
crypto
.
Keccak256
([]
byte
{
0x80
})
func
Decompress
(
dat
[]
byte
)
([]
byte
,
error
)
{
buf
:=
new
(
bytes
.
Buffer
)
for
i
:=
0
;
i
<
len
(
dat
);
i
++
{
if
dat
[
i
]
==
token
{
if
i
+
1
<
len
(
dat
)
{
switch
dat
[
i
+
1
]
{
case
emptyShaToken
:
buf
.
Write
(
empty
)
case
emptyListShaToken
:
buf
.
Write
(
emptyList
)
case
tokenToken
:
buf
.
WriteByte
(
token
)
default
:
buf
.
Write
(
make
([]
byte
,
int
(
dat
[
i
+
1
]
-
2
)))
}
i
++
}
else
{
return
nil
,
errors
.
New
(
"error reading bytes. token encountered without proceeding bytes"
)
}
}
else
{
buf
.
WriteByte
(
dat
[
i
])
}
}
return
buf
.
Bytes
(),
nil
}
func
compressChunk
(
dat
[]
byte
)
(
ret
[]
byte
,
n
int
)
{
switch
{
case
dat
[
0
]
==
token
:
return
[]
byte
{
token
,
tokenToken
},
1
case
len
(
dat
)
>
1
&&
dat
[
0
]
==
0x0
&&
dat
[
1
]
==
0x0
:
j
:=
0
for
j
<=
254
&&
j
<
len
(
dat
)
{
if
dat
[
j
]
!=
0
{
break
}
j
++
}
return
[]
byte
{
token
,
byte
(
j
+
2
)},
j
case
len
(
dat
)
>=
32
:
if
dat
[
0
]
==
empty
[
0
]
&&
bytes
.
Equal
(
dat
[
:
32
],
empty
)
{
return
[]
byte
{
token
,
emptyShaToken
},
32
}
else
if
dat
[
0
]
==
emptyList
[
0
]
&&
bytes
.
Equal
(
dat
[
:
32
],
emptyList
)
{
return
[]
byte
{
token
,
emptyListShaToken
},
32
}
fallthrough
default
:
return
dat
[
:
1
],
1
}
}
func
Compress
(
dat
[]
byte
)
[]
byte
{
buf
:=
new
(
bytes
.
Buffer
)
i
:=
0
for
i
<
len
(
dat
)
{
b
,
n
:=
compressChunk
(
dat
[
i
:
])
buf
.
Write
(
b
)
i
+=
n
}
return
buf
.
Bytes
()
}
compression/rle/read_write_test.go
已删除
100644 → 0
浏览文件 @
315b9b18
// Copyright 2014 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package
rle
import
(
"testing"
checker
"gopkg.in/check.v1"
)
func
Test
(
t
*
testing
.
T
)
{
checker
.
TestingT
(
t
)
}
type
CompressionRleSuite
struct
{}
var
_
=
checker
.
Suite
(
&
CompressionRleSuite
{})
func
(
s
*
CompressionRleSuite
)
TestDecompressSimple
(
c
*
checker
.
C
)
{
exp
:=
[]
byte
{
0xc5
,
0xd2
,
0x46
,
0x1
,
0x86
,
0xf7
,
0x23
,
0x3c
,
0x92
,
0x7e
,
0x7d
,
0xb2
,
0xdc
,
0xc7
,
0x3
,
0xc0
,
0xe5
,
0x0
,
0xb6
,
0x53
,
0xca
,
0x82
,
0x27
,
0x3b
,
0x7b
,
0xfa
,
0xd8
,
0x4
,
0x5d
,
0x85
,
0xa4
,
0x70
}
res
,
err
:=
Decompress
([]
byte
{
token
,
0xfd
})
c
.
Assert
(
err
,
checker
.
IsNil
)
c
.
Assert
(
res
,
checker
.
DeepEquals
,
exp
)
exp
=
[]
byte
{
0x56
,
0xe8
,
0x1f
,
0x17
,
0x1b
,
0xcc
,
0x55
,
0xa6
,
0xff
,
0x83
,
0x45
,
0xe6
,
0x92
,
0xc0
,
0xf8
,
0x6e
,
0x5b
,
0x48
,
0xe0
,
0x1b
,
0x99
,
0x6c
,
0xad
,
0xc0
,
0x1
,
0x62
,
0x2f
,
0xb5
,
0xe3
,
0x63
,
0xb4
,
0x21
}
res
,
err
=
Decompress
([]
byte
{
token
,
0xfe
})
c
.
Assert
(
err
,
checker
.
IsNil
)
c
.
Assert
(
res
,
checker
.
DeepEquals
,
exp
)
res
,
err
=
Decompress
([]
byte
{
token
,
0xff
})
c
.
Assert
(
err
,
checker
.
IsNil
)
c
.
Assert
(
res
,
checker
.
DeepEquals
,
[]
byte
{
token
})
res
,
err
=
Decompress
([]
byte
{
token
,
12
})
c
.
Assert
(
err
,
checker
.
IsNil
)
c
.
Assert
(
res
,
checker
.
DeepEquals
,
make
([]
byte
,
10
))
}
ethdb/database.go
浏览文件 @
0fac705e
...
...
@@ -91,9 +91,6 @@ func (db *LDBDatabase) Path() string {
// Put puts the given key / value to the queue
func
(
db
*
LDBDatabase
)
Put
(
key
[]
byte
,
value
[]
byte
)
error
{
// Generate the data to write to disk, update the meter and write
//value = rle.Compress(value)
return
db
.
db
.
Put
(
key
,
value
,
nil
)
}
...
...
@@ -103,18 +100,15 @@ func (db *LDBDatabase) Has(key []byte) (bool, error) {
// Get returns the given key if it's present.
func
(
db
*
LDBDatabase
)
Get
(
key
[]
byte
)
([]
byte
,
error
)
{
// Retrieve the key and increment the miss counter if not found
dat
,
err
:=
db
.
db
.
Get
(
key
,
nil
)
if
err
!=
nil
{
return
nil
,
err
}
return
dat
,
nil
//return rle.Decompress(dat)
}
// Delete deletes the key from the queue and database
func
(
db
*
LDBDatabase
)
Delete
(
key
[]
byte
)
error
{
// Execute the actual operation
return
db
.
db
.
Delete
(
key
,
nil
)
}
...
...
swarm/storage/database.go
浏览文件 @
0fac705e
...
...
@@ -22,7 +22,6 @@ package storage
import
(
"fmt"
"github.com/ethereum/go-ethereum/compression/rle"
"github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/iterator"
"github.com/syndtr/goleveldb/leveldb/opt"
...
...
@@ -31,8 +30,7 @@ import (
const
openFileLimit
=
128
type
LDBDatabase
struct
{
db
*
leveldb
.
DB
comp
bool
db
*
leveldb
.
DB
}
func
NewLDBDatabase
(
file
string
)
(
*
LDBDatabase
,
error
)
{
...
...
@@ -42,16 +40,12 @@ func NewLDBDatabase(file string) (*LDBDatabase, error) {
return
nil
,
err
}
database
:=
&
LDBDatabase
{
db
:
db
,
comp
:
false
}
database
:=
&
LDBDatabase
{
db
:
db
}
return
database
,
nil
}
func
(
self
*
LDBDatabase
)
Put
(
key
[]
byte
,
value
[]
byte
)
{
if
self
.
comp
{
value
=
rle
.
Compress
(
value
)
}
err
:=
self
.
db
.
Put
(
key
,
value
,
nil
)
if
err
!=
nil
{
fmt
.
Println
(
"Error put"
,
err
)
...
...
@@ -63,11 +57,6 @@ func (self *LDBDatabase) Get(key []byte) ([]byte, error) {
if
err
!=
nil
{
return
nil
,
err
}
if
self
.
comp
{
return
rle
.
Decompress
(
dat
)
}
return
dat
,
nil
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录