mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-27 08:42:14 +01:00
684b7a999f
* Dump: Use mholt/archive/v3 to support tar including many compressions Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: Allow dump output to stdout Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: Fixed bug present since #6677 where SessionConfig.Provider is never "file" Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: never pack RepoRootPath, LFS.ContentPath and LogRootPath when they are below AppDataPath Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: also dump LFS (fixes #10058) Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Dump: never dump CustomPath if CustomPath is a subdir of or equal to AppDataPath (fixes #10365) Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * Use log.Info instead of fmt.Fprintf Signed-off-by: Philipp Homann <homann.philipp@googlemail.com> * import ordering * make fmt Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io> Co-authored-by: Matti R <matti@mdranta.net>
69 lines
1.8 KiB
Go
Vendored
69 lines
1.8 KiB
Go
Vendored
// Copyright 2014-2017 Ulrich Kunitz. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package lzma
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// maximum and minimum values for the LZMA properties.
|
|
const (
|
|
minPB = 0
|
|
maxPB = 4
|
|
)
|
|
|
|
// maxPropertyCode is the possible maximum of a properties code byte.
|
|
const maxPropertyCode = (maxPB+1)*(maxLP+1)*(maxLC+1) - 1
|
|
|
|
// Properties contains the parameters LC, LP and PB. The parameter LC
|
|
// defines the number of literal context bits; parameter LP the number
|
|
// of literal position bits and PB the number of position bits.
|
|
type Properties struct {
|
|
LC int
|
|
LP int
|
|
PB int
|
|
}
|
|
|
|
// String returns the properties in a string representation.
|
|
func (p *Properties) String() string {
|
|
return fmt.Sprintf("LC %d LP %d PB %d", p.LC, p.LP, p.PB)
|
|
}
|
|
|
|
// PropertiesForCode converts a properties code byte into a Properties value.
|
|
func PropertiesForCode(code byte) (p Properties, err error) {
|
|
if code > maxPropertyCode {
|
|
return p, errors.New("lzma: invalid properties code")
|
|
}
|
|
p.LC = int(code % 9)
|
|
code /= 9
|
|
p.LP = int(code % 5)
|
|
code /= 5
|
|
p.PB = int(code % 5)
|
|
return p, err
|
|
}
|
|
|
|
// verify checks the properties for correctness.
|
|
func (p *Properties) verify() error {
|
|
if p == nil {
|
|
return errors.New("lzma: properties are nil")
|
|
}
|
|
if !(minLC <= p.LC && p.LC <= maxLC) {
|
|
return errors.New("lzma: lc out of range")
|
|
}
|
|
if !(minLP <= p.LP && p.LP <= maxLP) {
|
|
return errors.New("lzma: lp out of range")
|
|
}
|
|
if !(minPB <= p.PB && p.PB <= maxPB) {
|
|
return errors.New("lzma: pb out of range")
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Code converts the properties to a byte. The function assumes that
|
|
// the properties components are all in range.
|
|
func (p Properties) Code() byte {
|
|
return byte((p.PB*5+p.LP)*9 + p.LC)
|
|
}
|