1
0

wireformat.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. //
  3. // This program is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by the Free
  5. // Software Foundation, either version 3 of the License, or (at your option)
  6. // any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful, but WITHOUT
  9. // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. // more details.
  12. //
  13. // You should have received a copy of the GNU General Public License along
  14. // with this program. If not, see <http://www.gnu.org/licenses/>.
  15. package protocol
  16. import (
  17. "path/filepath"
  18. "code.google.com/p/go.text/unicode/norm"
  19. )
  20. type wireFormatConnection struct {
  21. next Connection
  22. }
  23. func (c wireFormatConnection) ID() DeviceID {
  24. return c.next.ID()
  25. }
  26. func (c wireFormatConnection) Name() string {
  27. return c.next.Name()
  28. }
  29. func (c wireFormatConnection) Index(folder string, fs []FileInfo) error {
  30. var myFs = make([]FileInfo, len(fs))
  31. copy(myFs, fs)
  32. for i := range fs {
  33. myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
  34. }
  35. return c.next.Index(folder, myFs)
  36. }
  37. func (c wireFormatConnection) IndexUpdate(folder string, fs []FileInfo) error {
  38. var myFs = make([]FileInfo, len(fs))
  39. copy(myFs, fs)
  40. for i := range fs {
  41. myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
  42. }
  43. return c.next.IndexUpdate(folder, myFs)
  44. }
  45. func (c wireFormatConnection) Request(folder, name string, offset int64, size int) ([]byte, error) {
  46. name = norm.NFC.String(filepath.ToSlash(name))
  47. return c.next.Request(folder, name, offset, size)
  48. }
  49. func (c wireFormatConnection) ClusterConfig(config ClusterConfigMessage) {
  50. c.next.ClusterConfig(config)
  51. }
  52. func (c wireFormatConnection) Statistics() Statistics {
  53. return c.next.Statistics()
  54. }