(defaultMessageEncoding MessageEncoding)
| 752 | } |
| 753 | |
| 754 | func newProcessRawRefMessage(defaultMessageEncoding MessageEncoding) func(*internal.RawRef) error { |
| 755 | return func(rawRef *internal.RawRef) error { |
| 756 | defaultFormat, ok := messageEncodingToFormat[defaultMessageEncoding] |
| 757 | if !ok { |
| 758 | // This is a system error. |
| 759 | return syserror.Newf("unknown MessageEncoding: %v", defaultMessageEncoding) |
| 760 | } |
| 761 | // if format option is not set and path is "-", default to bin |
| 762 | var format string |
| 763 | var compressionType internal.CompressionType |
| 764 | if rawRef.Path == "-" || app.IsDevNull(rawRef.Path) || app.IsDevStdin(rawRef.Path) || app.IsDevStdout(rawRef.Path) { |
| 765 | format = defaultFormat |
| 766 | } else { |
| 767 | switch filepath.Ext(rawRef.Path) { |
| 768 | case ".bin", ".binpb": |
| 769 | format = formatBinpb |
| 770 | case ".json": |
| 771 | format = formatJSON |
| 772 | case ".txtpb": |
| 773 | format = formatTxtpb |
| 774 | case ".yaml": |
| 775 | format = formatYAML |
| 776 | case ".gz": |
| 777 | compressionType = internal.CompressionTypeGzip |
| 778 | switch filepath.Ext(strings.TrimSuffix(rawRef.Path, filepath.Ext(rawRef.Path))) { |
| 779 | case ".bin", ".binpb": |
| 780 | format = formatBinpb |
| 781 | case ".json": |
| 782 | format = formatJSON |
| 783 | case ".txtpb": |
| 784 | format = formatTxtpb |
| 785 | case ".yaml": |
| 786 | format = formatYAML |
| 787 | default: |
| 788 | return fmt.Errorf("path %q had .gz extension with unknown format", rawRef.Path) |
| 789 | } |
| 790 | case ".zst": |
| 791 | compressionType = internal.CompressionTypeZstd |
| 792 | switch filepath.Ext(strings.TrimSuffix(rawRef.Path, filepath.Ext(rawRef.Path))) { |
| 793 | case ".bin", ".binpb": |
| 794 | format = formatBinpb |
| 795 | case ".json": |
| 796 | format = formatJSON |
| 797 | case ".txtpb": |
| 798 | format = formatTxtpb |
| 799 | case ".yaml": |
| 800 | format = formatYAML |
| 801 | default: |
| 802 | return fmt.Errorf("path %q had .zst extension with unknown format", rawRef.Path) |
| 803 | } |
| 804 | default: |
| 805 | format = defaultFormat |
| 806 | } |
| 807 | } |
| 808 | rawRef.Format = format |
| 809 | rawRef.CompressionType = compressionType |
| 810 | return nil |
| 811 | } |
no test coverage detected
searching dependent graphs…