wireformat.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (C) 2014 The Protocol Authors.
  2. package protocol
  3. import (
  4. "context"
  5. "path/filepath"
  6. "golang.org/x/text/unicode/norm"
  7. )
  8. type wireFormatConnection struct {
  9. Connection
  10. }
  11. func (c wireFormatConnection) Index(ctx context.Context, folder string, fs []FileInfo) error {
  12. var myFs = make([]FileInfo, len(fs))
  13. copy(myFs, fs)
  14. for i := range fs {
  15. myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
  16. }
  17. return c.Connection.Index(ctx, folder, myFs)
  18. }
  19. func (c wireFormatConnection) IndexUpdate(ctx context.Context, folder string, fs []FileInfo) error {
  20. var myFs = make([]FileInfo, len(fs))
  21. copy(myFs, fs)
  22. for i := range fs {
  23. myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
  24. }
  25. return c.Connection.IndexUpdate(ctx, folder, myFs)
  26. }
  27. func (c wireFormatConnection) Request(ctx context.Context, folder string, name string, blockNo int, offset int64, size int, hash []byte, weakHash uint32, fromTemporary bool) ([]byte, error) {
  28. name = norm.NFC.String(filepath.ToSlash(name))
  29. return c.Connection.Request(ctx, folder, name, blockNo, offset, size, hash, weakHash, fromTemporary)
  30. }