-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathfile.go
More file actions
1012 lines (964 loc) · 24.3 KB
/
file.go
File metadata and controls
1012 lines (964 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* zipindex, (C)2021 MinIO, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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 zipindex
import (
"encoding/binary"
"errors"
"fmt"
"hash/crc32"
"io"
"path/filepath"
"sort"
"strings"
"sync"
"github.com/klauspost/compress/zstd"
"github.com/tinylib/msgp/msgp"
)
//go:generate msgp -file $GOFILE -unexported
// File is a sparse representation of a File inside a zip file.
//
//msgp:tuple File
type File struct {
Name string // Name of the file as stored in the zip.
CompressedSize64 uint64 // Size of compressed data, excluding ZIP headers.
UncompressedSize64 uint64 // Size of the Uncompressed data.
Offset int64 // Offset where file data header starts.
CRC32 uint32 // CRC of the uncompressed data.
Method uint16 // Storage method.
Flags uint16 // General purpose bit flag
// Custom data.
Custom map[string]string
}
// Open returns a ReadCloser that provides access to the File's contents.
// The Reader 'r' must be forwarded to f.Offset before being provided.
func (f *File) Open(r io.Reader) (io.ReadCloser, error) {
if err := f.skipToBody(r); err != nil {
return nil, err
}
size := int64(f.CompressedSize64)
dcomp := decompressor(f.Method)
if dcomp == nil {
return nil, ErrAlgorithm
}
compReader := io.LimitReader(r, size)
var rc = dcomp(compReader)
rc = &checksumReader{
compReader: compReader,
rc: rc,
hash: crc32.NewIEEE(),
f: f,
raw: r,
}
return rc, nil
}
// OpenRaw returns a Reader that returns the *compressed* output of the file.
func (f *File) OpenRaw(r io.Reader) (io.Reader, error) {
if err := f.skipToBody(r); err != nil {
return nil, err
}
return io.LimitReader(r, int64(f.CompressedSize64)), nil
}
// Files is a collection of files.
//
//msgp:ignore Files
type Files []File
// unexported type to hide generated serialization functions.
type files []File
// Any changes to the file format MUST cause an increment here and MUST
// be backwards compatible.
const currentVerPlain = 1
const currentVerCompressed = 2
const currentVerCompressedStructs = 3
const currentVerCompressedStructsChunked = 4
var zstdEnc, _ = zstd.NewWriter(nil, zstd.WithWindowSize(128<<10), zstd.WithEncoderConcurrency(2), zstd.WithEncoderLevel(zstd.SpeedBetterCompression))
var zstdDec, _ = zstd.NewReader(nil, zstd.WithDecoderLowmem(true), zstd.WithDecoderConcurrency(2), zstd.WithDecoderMaxMemory(MaxIndexSize), zstd.WithDecoderMaxWindow(8<<20))
//msgp:tuple filesAsStructs
type filesAsStructs struct {
Names [][]byte
CSizes []int64
USizes []int64
Offsets []int64
Methods []uint16
Flags []uint16
Crcs []byte
Custom [][]byte
}
// Serialize the files.
func (f Files) Serialize() ([]byte, error) {
if len(f) > MaxFiles {
return nil, ErrTooManyFiles
}
if len(f) < 10 {
for _, file := range f {
if len(file.Custom) > MaxCustomEntries {
return nil, ErrTooManyCustomEntries
}
}
payload, err := files(f).MarshalMsg(nil)
if err != nil {
return nil, err
}
res := make([]byte, 0, len(payload))
if len(payload) < 200 {
res = append(res, currentVerPlain)
return append(res, payload...), nil
}
res = append(res, currentVerCompressed)
return zstdEnc.EncodeAll(payload, res), nil
}
const chunkN = 25000
if len(f) < chunkN {
return f.encodeAoS(nil)
}
f.SortByName()
res := append([]byte{}, currentVerCompressedStructsChunked)
left := f
var tmp []byte
for len(left) > 0 {
todo := left
if len(left) < chunkN*2 && len(left) > chunkN {
todo = left[:len(left)/2]
} else if len(left) > chunkN {
todo = left[:chunkN]
}
ch := chunk{
Files: len(todo),
First: todo[0].Name,
Last: todo[len(todo)-1].Name,
}
// Sort each chunk for smaller offsets.
todo.Sort()
var err error
tmp, err = todo.encodeAoS(tmp[:0])
if err != nil {
return nil, err
}
ch.Payload = tmp
res, err = ch.MarshalMsg(res)
if err != nil {
return nil, err
}
left = left[len(todo):]
}
return res, nil
}
func (f Files) encodeAoS(res []byte) ([]byte, error) {
// Encode many files as struct of arrays...
x := filesAsStructs{
Names: make([][]byte, len(f)),
CSizes: make([]int64, len(f)),
USizes: make([]int64, len(f)),
Offsets: make([]int64, len(f)),
Methods: make([]uint16, len(f)),
Flags: make([]uint16, len(f)),
Crcs: make([]byte, len(f)*4),
Custom: make([][]byte, len(f)),
}
for i, file := range f {
x.CSizes[i] = int64(file.CompressedSize64)
if i > 0 {
// Try to predict offset from previous file..
file.Offset -= f[i-1].Offset + int64(f[i-1].CompressedSize64) + fileHeaderLen + int64(len(f[i-1].Name)+dataDescriptorLen)
// Only encode when method changes.
file.Method ^= f[i-1].Method
file.Flags ^= f[i-1].Flags
// Use previous size as base.
x.CSizes[i] = int64(file.CompressedSize64) - int64(f[i-1].CompressedSize64)
}
x.Names[i] = []byte(file.Name)
// Uncompressed size is the size from the compressed.
x.USizes[i] = int64(file.UncompressedSize64) - int64(f[i].CompressedSize64)
x.Offsets[i] = file.Offset
x.Methods[i] = file.Method
x.Flags[i] = file.Flags
binary.LittleEndian.PutUint32(x.Crcs[i*4:], file.CRC32)
if len(file.Custom) > 0 {
if len(file.Custom) > MaxCustomEntries {
return nil, ErrTooManyCustomEntries
}
x.Custom[i] = msgp.AppendMapStrStr(nil, file.Custom)
}
}
payload, err := x.MarshalMsg(nil)
if err != nil {
return nil, err
}
res = append(res, currentVerCompressedStructs)
return zstdEnc.EncodeAll(payload, res), nil
}
// RemoveInsecurePaths will remove any file with path deemed insecure.
// This is files that fail either !filepath.IsLocal(file.Name) or contain a backslash.
func (f *Files) RemoveInsecurePaths() {
files := *f
for i, file := range files {
if file.Name == "" {
// Zip permits an empty file name field.
continue
}
// The zip specification states that names must use forward slashes,
// so consider any backslashes in the name insecure.
if !filepath.IsLocal(file.Name) || strings.Contains(file.Name, `\`) {
files = append(files[:i], files[:i+1]...)
}
}
*f = files
}
// Sort files by offset in zip file.
// Typically, directories are already sorted by offset.
// This will usually provide the smallest possible serialized size.
func (f Files) Sort() {
less := func(i, j int) bool {
a, b := f[i], f[j]
return a.Offset < b.Offset
}
if !sort.SliceIsSorted(f, less) {
sort.Slice(f, less)
}
}
// SortByName will sort files by file name in zip file.
func (f Files) SortByName() {
less := func(i, j int) bool {
a, b := f[i], f[j]
if a.Name != b.Name {
return a.Name < b.Name
}
return a.Offset < b.Offset
}
if !sort.SliceIsSorted(f, less) {
sort.Slice(f, less)
}
}
// Find the file with the provided name.
// Search is linear.
func (f Files) Find(name string) *File {
for _, file := range f {
if file.Name == name {
return &file
}
}
return nil
}
// OptimizeSize will sort entries and strip CRC data when the file has a file descriptor.
func (f Files) OptimizeSize() {
f.Sort()
f.StripCRC(false)
}
// StripCRC will zero out the CRC for all files if there is a data descriptor
// (which will contain a CRC) or optionally for all.
func (f Files) StripCRC(all bool) {
for i, file := range f {
if all || file.hasDataDescriptor() {
f[i].CRC32 = 0
}
}
}
// StripFlags will zero out the Flags, except the ones provided in mask.
func (f Files) StripFlags(mask uint16) {
for i, file := range f {
f[i].Flags = file.Flags & mask
}
}
var decompBuffer sync.Pool
// unpackPayload unpacks and optionally decompresses the payload.
func unpackPayload(b []byte) (payload []byte, typ byte, newBuf bool, err error) {
if len(b) < 1 {
return nil, 0, false, io.ErrUnexpectedEOF
}
if len(b) > MaxIndexSize {
return nil, 0, false, ErrMaxSizeExceeded
}
var out []byte
typ = b[0]
switch typ {
case currentVerPlain, currentVerCompressedStructsChunked:
out = b[1:]
case currentVerCompressed, currentVerCompressedStructs:
newBuf = true
dst, _ := decompBuffer.Get().([]byte)
// It is ok if we get a nil buffer, the decoder will allocate.
decoded, err := zstdDec.DecodeAll(b[1:], dst[:0])
if err != nil {
switch err {
case zstd.ErrDecoderSizeExceeded, zstd.ErrWindowSizeExceeded:
err = ErrMaxSizeExceeded
}
decompBuffer.Put(dst)
return nil, typ, false, err
}
out = decoded
default:
return nil, typ, false, errors.New("unknown version")
}
return out, typ, newBuf, nil
}
// DeserializeFiles will de-serialize the files.
func DeserializeFiles(b []byte) (Files, error) {
b, typ, newBuf, err := unpackPayload(b)
if err != nil {
return nil, err
}
if newBuf {
defer decompBuffer.Put(b)
}
if typ == currentVerCompressed || typ == currentVerPlain {
var dst files
// Check number of files.
nFiles, _, err := msgp.ReadArrayHeaderBytes(b)
if nFiles > 100 {
return nil, ErrTooManyFiles
}
if err != nil {
return nil, err
}
_, err = dst.UnmarshalMsg(b)
return Files(dst), err
}
if typ == currentVerCompressedStructsChunked {
var dst Files
var c chunk
tmp, _ := decompBuffer.Get().([]byte)
defer func() {
if tmp != nil {
decompBuffer.Put(tmp)
}
}()
for len(b) > 0 {
b, err = c.UnmarshalMsgZC(b)
if err != nil {
return nil, err
}
if len(c.Payload) == 0 {
return nil, errors.New("missing payload")
}
switch c.Payload[0] {
case currentVerCompressedStructs:
tmp, err = zstdDec.DecodeAll(c.Payload[1:], tmp[:0])
if err != nil {
return nil, err
}
dst, err = deserializeAoS(tmp, dst)
if err != nil {
return nil, err
}
default:
return nil, errors.New("unknown version")
}
}
return dst, nil
}
return deserializeAoS(b, nil)
}
func deserializeAoS(b []byte, files Files) (Files, error) {
var dst filesAsStructs
var err error
if _, err = dst.UnmarshalMsg(b); err != nil {
return nil, err
}
start := len(files)
files = append(files, make(Files, len(dst.Names))...)
add := files[start:]
var cur File
for i := range add {
cur = File{
Name: string(dst.Names[i]),
CompressedSize64: uint64(dst.CSizes[i] + int64(cur.CompressedSize64)),
CRC32: binary.LittleEndian.Uint32(dst.Crcs[i*4:]),
Method: dst.Methods[i] ^ cur.Method,
Flags: dst.Flags[i] ^ cur.Flags,
}
cur.UncompressedSize64 = uint64(dst.USizes[i] + int64(cur.CompressedSize64))
if i == 0 {
cur.Offset = dst.Offsets[i]
} else {
cur.Offset = dst.Offsets[i] + add[i-1].Offset + int64(add[i-1].CompressedSize64) + fileHeaderLen + int64(len(add[i-1].Name)) + dataDescriptorLen
}
if len(dst.Custom[i]) > 0 {
if cur.Custom, err = readCustomData(dst.Custom[i]); err != nil {
return nil, err
}
}
add[i] = cur
}
return files, err
}
func readCustomData(bts []byte) (dst map[string]string, err error) {
var zb0002 uint32
zb0002, bts, err = msgp.ReadMapHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom")
return
}
if zb0002 > MaxCustomEntries {
err = msgp.WrapError(ErrTooManyCustomEntries, "Custom", zb0002)
return
}
dst = make(map[string]string, zb0002)
for zb0002 > 0 {
var za0001 string
var za0002 string
zb0002--
za0001, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom")
return
}
za0002, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom", za0001)
return
}
dst[za0001] = za0002
}
return dst, nil
}
// FindSerialized will locate a file by name and return it.
// This will be less resource intensive than decoding all files,
// if only one it requested.
// Expected speed scales O(n) for n files.
// Returns nil, io.EOF if not found.
func FindSerialized(b []byte, name string) (*File, error) {
buf, typ, newBuf, err := unpackPayload(b)
if err != nil {
return nil, err
}
if newBuf {
defer decompBuffer.Put(buf)
}
if typ == currentVerCompressed || typ == currentVerPlain {
n, buf, err := msgp.ReadArrayHeaderBytes(buf)
if err != nil {
return nil, err
}
if n > 100 {
return nil, ErrTooManyFiles
}
var f File
for i := 0; i < int(n); i++ {
buf, err = f.UnmarshalMsg(buf)
if err != nil {
return nil, err
}
if f.Name == name {
return &f, nil
}
}
return nil, io.EOF
}
if typ == currentVerCompressedStructsChunked {
var c chunk
for len(buf) > 0 {
buf, err = c.UnmarshalMsgZC(buf)
if err != nil {
return nil, err
}
if name < c.First {
return nil, io.EOF
}
if name >= c.First && name <= c.Last {
if len(c.Payload) == 0 {
return nil, errors.New("missing payload")
}
buf = c.Payload
if buf[0] != currentVerCompressedStructs {
return nil, errors.New("unknown chunk")
}
dst, _ := decompBuffer.Get().([]byte)
defer decompBuffer.Put(dst)
buf, err = zstdDec.DecodeAll(buf[1:], dst[:0])
if err != nil {
return nil, err
}
break
}
if len(buf) == 0 {
return nil, io.EOF
}
}
}
// Files are packed as an array of arrays...
idx := -1
var zb0001 uint32
bts := buf
zb0001, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Files")
return nil, err
}
const arraySize = 8
if zb0001 != arraySize {
err = msgp.ArrayError{Wanted: arraySize, Got: zb0001}
return nil, err
}
var nFiles uint32
nFiles, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Names")
return nil, err
}
if nFiles > MaxFiles {
return nil, ErrTooManyFiles
}
// We accumulate values needed for cur as we parse...
var cur File
for i := 0; i < int(nFiles); i++ {
var got []byte
got, bts, err = msgp.ReadBytesZC(bts)
if err != nil {
err = msgp.WrapError(err, "Names-Field")
return nil, err
}
if idx >= 0 {
continue
}
if string(got) == name {
idx = i
continue
}
// Names add to offset...
cur.Offset += int64(len(got))
}
if idx < 0 {
return nil, io.EOF
}
cur.Name = name
for field := 0; field < arraySize-1; field++ {
// CRC is just a single array.
if field == 5 {
var Crcs []byte
Crcs, bts, err = msgp.ReadBytesZC(bts)
if err != nil {
err = msgp.WrapError(err, "Crcs")
return nil, err
}
if len(Crcs) != int(nFiles*4) {
return nil, fmt.Errorf("CRC field too short, want %d, got %d", int(nFiles*4), len(Crcs))
}
cur.CRC32 = binary.LittleEndian.Uint32(Crcs[idx*4:])
continue
}
var elems uint32
elems, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, fmt.Sprintf("field-%d", field))
return nil, err
}
if elems != nFiles {
return nil, fmt.Errorf("unexpected array size, got %d, want %d", elems, nFiles)
}
for i := 0; i < int(nFiles); i++ {
var val64 int64
switch field {
case 0: // CSizes []int64
val64, bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "CSizes")
return nil, err
}
if i > idx {
continue
}
cur.CompressedSize64 = uint64(int64(cur.CompressedSize64) + val64)
if i < idx {
// Compressed size adds to offset for all before idx.
cur.Offset += int64(cur.CompressedSize64)
}
case 1: // USizes []int64
val64, bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "USizes")
return nil, err
}
if i > idx {
continue
}
cur.UncompressedSize64 = uint64(int64(cur.CompressedSize64) + val64)
case 2: // Offsets []int64
val64, bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Offsets")
return nil, err
}
if i > idx {
continue
}
// Offset adds to offset
cur.Offset += val64
if i > 0 {
// Add constants...
cur.Offset += fileHeaderLen + dataDescriptorLen
}
case 3: // Methods []uint16
var val16 uint16
val16, bts, err = msgp.ReadUint16Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Methods")
return nil, err
}
if i > idx {
continue
}
cur.Method ^= val16
case 4: // Flags []uint16
var val16 uint16
val16, bts, err = msgp.ReadUint16Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Flags")
return nil, err
}
if i > idx {
continue
}
cur.Flags ^= val16
case 6: // Custom
var custom []byte
custom, bts, err = msgp.ReadBytesZC(bts)
if err != nil {
err = msgp.WrapError(err, fmt.Sprintf("field-%d", field))
return nil, err
}
if i != idx || len(custom) == 0 {
continue
}
cur.Custom, err = readCustomData(custom)
if err != nil {
err = msgp.WrapError(err, "Custom Data")
return nil, err
}
default:
panic("internal error, unexpected field")
}
}
}
return &cur, nil
}
//msgp:unmarshal ignore File
// UnmarshalMsg implements msgp.Unmarshaler
func (f *File) UnmarshalMsg(bts []byte) (o []byte, err error) {
var zb0001 uint32
zb0001, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err)
return
}
if zb0001 != 8 {
err = msgp.ArrayError{Wanted: 8, Got: zb0001}
return
}
f.Name, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Name")
return
}
f.CompressedSize64, bts, err = msgp.ReadUint64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "CompressedSize64")
return
}
f.UncompressedSize64, bts, err = msgp.ReadUint64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "UncompressedSize64")
return
}
f.Offset, bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Offset")
return
}
f.CRC32, bts, err = msgp.ReadUint32Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "CRC32")
return
}
f.Method, bts, err = msgp.ReadUint16Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Method")
return
}
f.Flags, bts, err = msgp.ReadUint16Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Flags")
return
}
var zb0002 uint32
zb0002, bts, err = msgp.ReadMapHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom")
return
}
if zb0002 > MaxCustomEntries {
err = msgp.WrapError(ErrTooManyCustomEntries, "Custom", zb0002)
return
}
if f.Custom == nil {
f.Custom = make(map[string]string, zb0002)
} else if len(f.Custom) > 0 {
for key := range f.Custom {
delete(f.Custom, key)
}
}
for zb0002 > 0 {
var za0001 string
var za0002 string
zb0002--
za0001, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom")
return
}
za0002, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom", za0001)
return
}
f.Custom[za0001] = za0002
}
o = bts
return
}
//msgp:unmarshal ignore filesAsStructs
// UnmarshalMsg implements msgp.Unmarshaler
func (z *filesAsStructs) UnmarshalMsg(bts []byte) (o []byte, err error) {
var zb0001 uint32
zb0001, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err)
return
}
if zb0001 != 8 {
err = msgp.ArrayError{Wanted: 8, Got: zb0001}
return
}
var zb0002 uint32
zb0002, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Names")
return
}
if zb0002 > MaxFiles {
err = msgp.WrapError(err, "ErrTooManyFiles", zb0002)
return
}
if cap(z.Names) >= int(zb0002) {
z.Names = (z.Names)[:zb0002]
} else {
z.Names = make([][]byte, zb0002)
}
for za0001 := range z.Names {
z.Names[za0001], bts, err = msgp.ReadBytesBytes(bts, z.Names[za0001])
if err != nil {
err = msgp.WrapError(err, "Names", za0001)
return
}
}
var zb0003 uint32
zb0003, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "CSizes")
return
}
if zb0003 != zb0002 {
err = msgp.WrapError(errors.New("field number mismatch"), "CSizes", zb0003)
return
}
if cap(z.CSizes) >= int(zb0003) {
z.CSizes = (z.CSizes)[:zb0003]
} else {
z.CSizes = make([]int64, zb0003)
}
for za0002 := range z.CSizes {
z.CSizes[za0002], bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "CSizes", za0002)
return
}
}
var zb0004 uint32
zb0004, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "USizes")
return
}
if zb0004 != zb0002 {
err = msgp.WrapError(errors.New("field number mismatch"), "USizes", zb0004)
return
}
if cap(z.USizes) >= int(zb0004) {
z.USizes = (z.USizes)[:zb0004]
} else {
z.USizes = make([]int64, zb0004)
}
for za0003 := range z.USizes {
z.USizes[za0003], bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "USizes", za0003)
return
}
}
var zb0005 uint32
zb0005, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Offsets")
return
}
if zb0005 != zb0002 {
err = msgp.WrapError(errors.New("field number mismatch"), "Offsets", zb0005)
return
}
if cap(z.Offsets) >= int(zb0005) {
z.Offsets = (z.Offsets)[:zb0005]
} else {
z.Offsets = make([]int64, zb0005)
}
for za0004 := range z.Offsets {
z.Offsets[za0004], bts, err = msgp.ReadInt64Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Offsets", za0004)
return
}
}
var zb0006 uint32
zb0006, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Methods")
return
}
if zb0006 != zb0002 {
err = msgp.WrapError(errors.New("field number mismatch"), "Methods", zb0006)
return
}
if cap(z.Methods) >= int(zb0006) {
z.Methods = (z.Methods)[:zb0006]
} else {
z.Methods = make([]uint16, zb0006)
}
for za0005 := range z.Methods {
z.Methods[za0005], bts, err = msgp.ReadUint16Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Methods", za0005)
return
}
}
var zb0007 uint32
zb0007, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Flags")
return
}
if zb0007 != zb0002 {
err = msgp.WrapError(errors.New("field number mismatch"), "Flags", zb0007)
return
}
if cap(z.Flags) >= int(zb0007) {
z.Flags = (z.Flags)[:zb0007]
} else {
z.Flags = make([]uint16, zb0007)
}
for za0006 := range z.Flags {
z.Flags[za0006], bts, err = msgp.ReadUint16Bytes(bts)
if err != nil {
err = msgp.WrapError(err, "Flags", za0006)
return
}
}
z.Crcs, bts, err = msgp.ReadBytesBytes(bts, z.Crcs)
if err != nil {
err = msgp.WrapError(err, "Crcs")
return
}
var zb0008 uint32
zb0008, bts, err = msgp.ReadArrayHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Custom")
return
}
if zb0008 != zb0002 {
err = msgp.WrapError(errors.New("field number mismatch"), "Custom")
return
}
if cap(z.Custom) >= int(zb0008) {
z.Custom = (z.Custom)[:zb0008]
} else {
z.Custom = make([][]byte, zb0008)
}
for za0007 := range z.Custom {
z.Custom[za0007], bts, err = msgp.ReadBytesBytes(bts, z.Custom[za0007])
if err != nil {
err = msgp.WrapError(err, "Custom", za0007)
return
}
}
o = bts
return
}
type chunk struct {
Files int
First string
Last string
Payload []byte
}
// UnmarshalMsgZC unmarshals, but does a zero copy bytes
func (z *chunk) UnmarshalMsgZC(bts []byte) (o []byte, err error) {
var field []byte
_ = field
var zb0001 uint32
zb0001, bts, err = msgp.ReadMapHeaderBytes(bts)
if err != nil {
err = msgp.WrapError(err)
return
}
for zb0001 > 0 {
zb0001--
field, bts, err = msgp.ReadMapKeyZC(bts)
if err != nil {
err = msgp.WrapError(err)
return
}
switch msgp.UnsafeString(field) {
case "Files":
z.Files, bts, err = msgp.ReadIntBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Files")
return
}
case "First":
z.First, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "First")
return
}
case "Last":
z.Last, bts, err = msgp.ReadStringBytes(bts)
if err != nil {
err = msgp.WrapError(err, "Last")
return
}
case "Payload":
z.Payload, bts, err = msgp.ReadBytesZC(bts)
if err != nil {
err = msgp.WrapError(err, "Payload")
return