aboutsummaryrefslogtreecommitdiff
path: root/Sources/fileTypes.swift
blob: 221b7b2027780e993336456dcf1227d498778fc6 (plain)
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
//
//  fileTypes.swift
//
//
//  Created by Navan Chauhan on 12/3/23.
//

import Foundation

enum ResponseType {
  case string(String)
  case data(Data)
}

enum gopherFileType {
  case text
  case directory
  case nameserver
  case error
  case binhex
  case bindos
  case uuencoded
  case indexSearch
  case telnet
  case binary
  case redundantServer
  case tn3270Session
  case gif
  case image
  case bitmap
  case movie
  case sound
  case doc
  case html
  case message
  case png
  case rtf
  case wavfile
  case pdf
  case xml
}

func getFileType(fileExtension: String) -> gopherFileType {
  switch fileExtension {
  case "txt":
    return .text
  case "md":
    return .text
  case "html":
    return .html
  case "pdf":
    return .pdf
  case "png":
    return .png
  case "gif":
    return .gif
  case "jpg":
    return .image
  case "jpeg":
    return .image
  case "mp3":
    return .sound
  case "wav":
    return .wavfile
  case "mp4":
    return .movie
  case "mov":
    return .movie
  case "avi":
    return .movie
  case "rtf":
    return .rtf
  case "xml":
    return .xml
  default:
    return .binary
  }
}

func fileTypeToGopherItem(fileType: gopherFileType) -> String {
  switch fileType {
  case .text:
    return "0"
  case .directory:
    return "1"
  case .nameserver:
    return "2"
  case .error:
    return "3"
  case .binhex:
    return "4"
  case .bindos:
    return "5"
  case .uuencoded:
    return "6"
  case .indexSearch:
    return "7"
  case .telnet:
    return "8"
  case .binary:
    return "9"
  case .redundantServer:
    return "+"
  case .tn3270Session:
    return "T"
  case .gif:
    return "g"
  case .image:
    return "I"
  case .bitmap:
    return "b"
  case .movie:
    return "M"
  case .sound:
    return "s"
  case .doc:
    return "d"
  case .html:
    return "h"
  case .message:
    return "i"
  case .png:
    return "p"
  case .rtf:
    return "t"
  case .wavfile:
    return "w"
  case .pdf:
    return "P"
  case .xml:
    return "x"
  }
}