func addAndAssert(t *testing.T, name string, sizeS string) { size, _ := utils.BytesFromString(sizeS) rnd := randReader(size) f, err := S.Add(name, rnd, size) if err != nil { t.Errorf("Storage.Add(%s, %d) return err: %v", name, size, err) } fg, ok := S.Get(name) if !ok { t.Errorf("Storage.Get(%s) return false", name) } fg.Open() defer fg.Close() if fg != f { t.Error("Files not match") } if fg.FSize != size { t.Errorf("File sizes mismatch. Actual: %d, expected: %d", size, fg.FSize) } // check md5 h := md5.New() io.Copy(h, fg.GetReader()) act := fmt.Sprintf("%x", h.Sum(nil)) exp := fmt.Sprintf("%x", f.Md5) if act != exp { t.Error("Md5 file %s mismatch. Actual: %s, expected: %s", name, act, exp) } }
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package storage import ( "math" "utils" ) var R = Rounder{} var ( i1kb, _ = utils.BytesFromString("1k") i16kb, _ = utils.BytesFromString("16k") i128kb, _ = utils.BytesFromString("128k") i1mb, _ = utils.BytesFromString("1m") i4mb, _ = utils.BytesFromString("4m") ) type Rounder struct{} /** * 2,4,8,16..512,1024 - n2 * 1k,2k,3k...15k,16k - 1k * 16k,32k,48k..112k,128k - 16k * 128k,256k,384k..3968k,4096k - 128k * 4m,5m,6m... - 1mb **/