sfml.js 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (313) hide show
  1. package/README.ja.md +10 -9
  2. package/README.ko.md +10 -9
  3. package/README.md +10 -9
  4. package/README.zh-CN.md +10 -9
  5. package/binding.gyp +23 -16
  6. package/dist/audio/effect-processor.js +9 -3
  7. package/dist/audio/input-sound-file.js +41 -15
  8. package/dist/audio/listener.js +33 -11
  9. package/dist/audio/music.js +41 -18
  10. package/dist/audio/output-sound-file.js +4 -2
  11. package/dist/audio/playback-device.js +11 -3
  12. package/dist/audio/sound-buffer-recorder.js +8 -5
  13. package/dist/audio/sound-buffer.js +40 -17
  14. package/dist/audio/sound-file-factory.js +21 -9
  15. package/dist/audio/sound-file-reader.js +21 -7
  16. package/dist/audio/sound-recorder.js +36 -15
  17. package/dist/audio/sound-source.js +117 -40
  18. package/dist/audio/sound-stream.js +14 -5
  19. package/dist/audio/sound.js +9 -4
  20. package/dist/audio/value.js +42 -16
  21. package/dist/graphics/blend-mode.js +2 -1
  22. package/dist/graphics/boolean-vector.d.ts +1 -2
  23. package/dist/graphics/boolean-vector.js +19 -9
  24. package/dist/graphics/color.js +2 -1
  25. package/dist/graphics/convex-shape.js +7 -3
  26. package/dist/graphics/font.js +52 -23
  27. package/dist/graphics/glsl-matrix.js +8 -3
  28. package/dist/graphics/glsl.js +47 -16
  29. package/dist/graphics/glyph.js +27 -10
  30. package/dist/graphics/image.js +30 -14
  31. package/dist/graphics/rect.js +15 -8
  32. package/dist/graphics/render-states.js +18 -9
  33. package/dist/graphics/render-target.js +49 -23
  34. package/dist/graphics/render-texture.js +24 -12
  35. package/dist/graphics/render-window.js +6 -3
  36. package/dist/graphics/shader.js +67 -32
  37. package/dist/graphics/shape.js +25 -13
  38. package/dist/graphics/sprite.js +19 -9
  39. package/dist/graphics/stencil-mode.js +10 -6
  40. package/dist/graphics/swap.js +2 -1
  41. package/dist/graphics/text.js +123 -48
  42. package/dist/graphics/texture.js +48 -24
  43. package/dist/graphics/transform.js +29 -13
  44. package/dist/graphics/transformable.js +2 -1
  45. package/dist/graphics/vertex-array.js +40 -18
  46. package/dist/graphics/vertex-buffer.js +39 -19
  47. package/dist/graphics/vertex.js +6 -3
  48. package/dist/graphics/view.js +30 -14
  49. package/dist/index.d.ts +4 -4
  50. package/dist/internal/audio-codec-registry.js +12 -6
  51. package/dist/internal/audio-input-stream.js +2 -1
  52. package/dist/internal/audio-music-pump.js +58 -24
  53. package/dist/internal/audio-recorder-session.js +17 -7
  54. package/dist/internal/audio-worker-session.js +28 -10
  55. package/dist/internal/audio-worker.js +40 -21
  56. package/dist/internal/glsl-value.d.ts +3 -1
  57. package/dist/internal/glsl-value.js +18 -8
  58. package/dist/internal/graphics-state.js +29 -15
  59. package/dist/internal/input-stream.d.ts +3 -1
  60. package/dist/internal/input-stream.js +16 -7
  61. package/dist/internal/numeric-properties.js +2 -1
  62. package/dist/internal/render-states.js +2 -1
  63. package/dist/internal/scalar.js +22 -13
  64. package/dist/internal/shaped-glyph.d.ts +3 -1
  65. package/dist/internal/shaped-glyph.js +12 -4
  66. package/dist/internal/struct-view.d.ts +3 -1
  67. package/dist/internal/struct-view.js +3 -1
  68. package/dist/internal/transformable.js +2 -1
  69. package/dist/network/common.js +23 -11
  70. package/dist/network/dns.js +25 -17
  71. package/dist/network/ftp.js +43 -18
  72. package/dist/network/http.js +126 -56
  73. package/dist/network/ip-address.js +50 -25
  74. package/dist/network/packet.js +63 -25
  75. package/dist/network/sftp.js +175 -74
  76. package/dist/network/socket-selector.js +28 -14
  77. package/dist/network/socket.js +71 -30
  78. package/dist/network/tcp-listener.js +42 -19
  79. package/dist/network/tcp-socket.js +111 -53
  80. package/dist/network/tls-material.js +2 -1
  81. package/dist/network/udp-socket.js +68 -33
  82. package/dist/system/angle.js +2 -1
  83. package/dist/system/clock.js +4 -2
  84. package/dist/system/err.js +5 -2
  85. package/dist/system/file-input-stream.js +8 -4
  86. package/dist/system/input-stream.js +6 -3
  87. package/dist/system/operators.d.ts +1 -1
  88. package/dist/system/operators.js +90 -50
  89. package/dist/system/sleep.js +4 -2
  90. package/dist/system/time.js +12 -6
  91. package/dist/system/vector2.js +6 -7
  92. package/dist/system/vector3.js +11 -6
  93. package/dist/window/clipboard.js +2 -1
  94. package/dist/window/context.js +10 -5
  95. package/dist/window/cursor.js +2 -1
  96. package/dist/window/event.js +9 -5
  97. package/dist/window/mouse.js +4 -2
  98. package/dist/window/video-mode.js +2 -1
  99. package/dist/window/window.js +19 -12
  100. package/native/addon.cc +25 -12
  101. package/native/audio-binding.cc +266 -126
  102. package/native/audio-codec-binding.cc +147 -77
  103. package/native/audio-device-binding.cc +76 -49
  104. package/native/audio-file-binding.cc +116 -67
  105. package/native/audio-recorder-binding.cc +147 -98
  106. package/native/audio-recorder.h +1 -1
  107. package/native/audio-state.h +53 -30
  108. package/native/audio-stream-binding.cc +148 -94
  109. package/native/audio-stream.h +5 -4
  110. package/native/audio-worker-binding.cc +163 -81
  111. package/native/audio-worker.h +35 -19
  112. package/native/batch-drawable.cc +29 -16
  113. package/native/batch-drawable.h +11 -8
  114. package/native/context-binding.cc +40 -27
  115. package/native/context-settings.h +15 -8
  116. package/native/deferred-delete.cc +9 -6
  117. package/native/deferred-delete.h +7 -8
  118. package/native/error-stream-binding.cc +42 -28
  119. package/native/font-binding.cc +89 -48
  120. package/native/graphics-binding.cc +122 -72
  121. package/native/graphics-state.h +50 -36
  122. package/native/image-binding.cc +38 -24
  123. package/native/image-state.h +26 -18
  124. package/native/input-binding.cc +42 -27
  125. package/native/render-window-binding.cc +38 -23
  126. package/native/shader-binding.cc +115 -50
  127. package/native/shape-binding.cc +94 -49
  128. package/native/shape-state.h +18 -9
  129. package/native/shaped-glyph-storage.h +9 -5
  130. package/native/stream-binding.cc +143 -117
  131. package/native/system-binding.cc +17 -12
  132. package/native/text-binding.cc +68 -35
  133. package/native/text-state.h +25 -18
  134. package/native/texture-binding.cc +42 -33
  135. package/native/texture-resource.h +20 -12
  136. package/native/time-value.h +3 -1
  137. package/native/transformable-binding.cc +12 -6
  138. package/native/transformable-state.h +6 -6
  139. package/native/value-binding.h +46 -28
  140. package/native/value-layout.h +10 -10
  141. package/native/values-binding.cc +29 -23
  142. package/native/vertex-binding.cc +18 -12
  143. package/native/vertex-buffer-binding.cc +38 -24
  144. package/native/vertex-storage.h +2 -2
  145. package/native/view-data.h +4 -3
  146. package/native/window-binding.cc +75 -45
  147. package/native/window-event.h +20 -11
  148. package/native/window-owner.h +15 -12
  149. package/package.json +40 -48
  150. package/src/audio/effect-processor.ts +9 -3
  151. package/src/audio/input-sound-file.ts +108 -36
  152. package/src/audio/listener.ts +39 -13
  153. package/src/audio/music.ts +112 -47
  154. package/src/audio/output-sound-file.ts +40 -11
  155. package/src/audio/playback-device.ts +23 -8
  156. package/src/audio/sound-buffer-recorder.ts +35 -13
  157. package/src/audio/sound-buffer.ts +166 -58
  158. package/src/audio/sound-file-factory.ts +127 -49
  159. package/src/audio/sound-file-reader.ts +49 -15
  160. package/src/audio/sound-recorder.ts +100 -34
  161. package/src/audio/sound-source.ts +142 -45
  162. package/src/audio/sound-stream.ts +15 -5
  163. package/src/audio/sound.ts +12 -4
  164. package/src/audio/value.ts +89 -26
  165. package/src/graphics/blend-mode.ts +3 -1
  166. package/src/graphics/boolean-vector.ts +56 -26
  167. package/src/graphics/color.ts +3 -1
  168. package/src/graphics/convex-shape.ts +10 -3
  169. package/src/graphics/font.ts +171 -50
  170. package/src/graphics/glsl-matrix.ts +9 -3
  171. package/src/graphics/glsl.ts +81 -35
  172. package/src/graphics/glyph.ts +67 -26
  173. package/src/graphics/image.ts +119 -45
  174. package/src/graphics/rect.ts +56 -24
  175. package/src/graphics/render-states.ts +31 -14
  176. package/src/graphics/render-target.ts +197 -81
  177. package/src/graphics/render-texture.ts +36 -12
  178. package/src/graphics/render-window.ts +9 -3
  179. package/src/graphics/shader.ts +186 -61
  180. package/src/graphics/shape.ts +93 -35
  181. package/src/graphics/sprite.ts +64 -25
  182. package/src/graphics/stencil-mode.ts +12 -6
  183. package/src/graphics/swap.ts +3 -2
  184. package/src/graphics/text.ts +229 -74
  185. package/src/graphics/texture.ts +180 -61
  186. package/src/graphics/transform.ts +132 -47
  187. package/src/graphics/transformable.ts +3 -1
  188. package/src/graphics/vertex-array.ts +87 -35
  189. package/src/graphics/vertex-buffer.ts +97 -33
  190. package/src/graphics/vertex.ts +9 -3
  191. package/src/graphics/view.ts +59 -21
  192. package/src/index.ts +101 -23
  193. package/src/internal/audio-codec-registry.ts +18 -6
  194. package/src/internal/audio-input-stream.ts +6 -2
  195. package/src/internal/audio-music-pump.ts +116 -41
  196. package/src/internal/audio-native.ts +249 -96
  197. package/src/internal/audio-recorder-session.ts +68 -24
  198. package/src/internal/audio-worker-session.ts +65 -21
  199. package/src/internal/audio-worker.ts +85 -41
  200. package/src/internal/glsl-value.ts +26 -11
  201. package/src/internal/graphics-state.ts +57 -20
  202. package/src/internal/input-stream.ts +23 -10
  203. package/src/internal/native.ts +252 -99
  204. package/src/internal/numeric-properties.ts +2 -1
  205. package/src/internal/render-states.ts +3 -1
  206. package/src/internal/scalar.ts +33 -14
  207. package/src/internal/shaped-glyph.ts +25 -12
  208. package/src/internal/struct-view.ts +40 -13
  209. package/src/internal/transformable.ts +3 -1
  210. package/src/network/common.ts +35 -11
  211. package/src/network/dns.ts +95 -38
  212. package/src/network/ftp.ts +129 -47
  213. package/src/network/http.ts +232 -77
  214. package/src/network/ip-address.ts +118 -48
  215. package/src/network/packet.ts +161 -54
  216. package/src/network/sftp.ts +498 -168
  217. package/src/network/socket-selector.ts +66 -26
  218. package/src/network/socket.ts +133 -46
  219. package/src/network/tcp-listener.ts +78 -29
  220. package/src/network/tcp-socket.ts +240 -95
  221. package/src/network/tls-material.ts +6 -2
  222. package/src/network/udp-socket.ts +147 -53
  223. package/src/system/angle.ts +3 -1
  224. package/src/system/clock.ts +12 -4
  225. package/src/system/err.ts +5 -2
  226. package/src/system/file-input-stream.ts +12 -4
  227. package/src/system/input-stream.ts +9 -3
  228. package/src/system/operators.ts +290 -115
  229. package/src/system/sleep.ts +6 -2
  230. package/src/system/time.ts +18 -6
  231. package/src/system/timeout-with-predicate.ts +19 -8
  232. package/src/system/vector2.ts +101 -49
  233. package/src/system/vector3.ts +85 -36
  234. package/src/window/clipboard.ts +3 -1
  235. package/src/window/context.ts +15 -5
  236. package/src/window/cursor.ts +3 -1
  237. package/src/window/event.ts +26 -12
  238. package/src/window/mouse.ts +6 -2
  239. package/src/window/video-mode.ts +3 -1
  240. package/src/window/window.ts +119 -37
  241. package/test/native/audio-probes.cc +74 -36
  242. package/test/native/deferred-delete-probes.cc +17 -11
  243. package/test/native/drawable-probes.cc +70 -36
  244. package/test/native/exception-probes.cc +14 -9
  245. package/test/native/image-probes.cc +20 -10
  246. package/test/native/matrix-probes.cc +8 -4
  247. package/test/native/network-oracle.cc +17 -11
  248. package/test/native/render-texture-probes.cc +33 -24
  249. package/test/native/shader-probes.cc +9 -9
  250. package/test/native/shape-probes.cc +37 -23
  251. package/test/native/sprite-probes.cc +41 -25
  252. package/test/native/system-probes.cc +58 -35
  253. package/test/native/text-probes.cc +77 -44
  254. package/test/native/texture-probes.cc +43 -26
  255. package/test/native/time-probes.cc +18 -12
  256. package/test/native/transform-probes.cc +15 -10
  257. package/test/native/transformable-probes.cc +23 -17
  258. package/test/native/value-oracle.h +9 -4
  259. package/test/native/value-probes.cc +31 -23
  260. package/test/native/vertex-array-probes.cc +22 -14
  261. package/test/native/vertex-buffer-probes.cc +28 -17
  262. package/test/native/view-probes.cc +29 -17
  263. package/test/native/window-probes.cc +66 -33
  264. package/tools/ensure-sfml.cjs +9 -0
  265. package/tools/generate-network-constants.cjs +11 -6
  266. package/tools/generate-window-constants.cjs +31 -12
  267. package/docs/README.ja.md +0 -30
  268. package/docs/README.ko.md +0 -30
  269. package/docs/README.md +0 -30
  270. package/docs/README.zh-CN.md +0 -30
  271. package/docs/api.ja.md +0 -84
  272. package/docs/api.ko.md +0 -84
  273. package/docs/api.md +0 -81
  274. package/docs/api.zh-CN.md +0 -81
  275. package/docs/audio.ja.md +0 -249
  276. package/docs/audio.ko.md +0 -251
  277. package/docs/audio.md +0 -252
  278. package/docs/audio.zh-CN.md +0 -252
  279. package/docs/concepts.ja.md +0 -130
  280. package/docs/concepts.ko.md +0 -130
  281. package/docs/concepts.md +0 -131
  282. package/docs/concepts.zh-CN.md +0 -131
  283. package/docs/development.ja.md +0 -144
  284. package/docs/development.ko.md +0 -144
  285. package/docs/development.md +0 -146
  286. package/docs/development.zh-CN.md +0 -146
  287. package/docs/getting-started.ja.md +0 -154
  288. package/docs/getting-started.ko.md +0 -154
  289. package/docs/getting-started.md +0 -156
  290. package/docs/getting-started.zh-CN.md +0 -156
  291. package/docs/graphics.ja.md +0 -256
  292. package/docs/graphics.ko.md +0 -254
  293. package/docs/graphics.md +0 -255
  294. package/docs/graphics.zh-CN.md +0 -257
  295. package/docs/network.ja.md +0 -214
  296. package/docs/network.ko.md +0 -216
  297. package/docs/network.md +0 -218
  298. package/docs/network.zh-CN.md +0 -218
  299. package/docs/system.ja.md +0 -169
  300. package/docs/system.ko.md +0 -171
  301. package/docs/system.md +0 -173
  302. package/docs/system.zh-CN.md +0 -173
  303. package/docs/window.ja.md +0 -138
  304. package/docs/window.ko.md +0 -140
  305. package/docs/window.md +0 -141
  306. package/docs/window.zh-CN.md +0 -141
  307. package/native/exception-boundary.h +0 -97
  308. package/native/numeric-fields.h +0 -96
  309. package/native/shared-handle.h +0 -107
  310. package/test/tsconfig.json +0 -8
  311. package/tools/configure-lsp.cjs +0 -23
  312. package/tools/lib_downloader.cjs +0 -92
  313. package/tools/lib_downloader_urls.cjs +0 -23
@@ -5,7 +5,12 @@ import { Writable } from 'node:stream';
5
5
  import { basename, join, posix } from 'node:path';
6
6
  import { IpAddress } from './ip-address';
7
7
  import { Time } from '../system/time';
8
- import { SerialQueue, uint, millisecondsOf, type NetworkTime } from './common';
8
+ import {
9
+ SerialQueue,
10
+ uint,
11
+ millisecondsOf,
12
+ type NetworkTime,
13
+ } from './common';
9
14
  import { FtpStatus, TransferMode } from './gen/constants';
10
15
 
11
16
  export { FtpStatus, TransferMode } from './gen/constants';
@@ -29,8 +34,10 @@ export class FtpResponse {
29
34
  * @ja レスポンスを作成します。既定の状態は InvalidResponse です。
30
35
  * @ko 응답을 생성하며 기본 상태는 InvalidResponse입니다.
31
36
  */
32
- constructor(private readonly status: FtpStatus = FtpStatus.InvalidResponse,
33
- private readonly message = '') {}
37
+ constructor(
38
+ private readonly status: FtpStatus = FtpStatus.InvalidResponse,
39
+ private readonly message = '',
40
+ ) {}
34
41
  /**
35
42
  * Return whether the status code is below 400, including success
36
43
  * and responses requiring further action.
@@ -40,21 +47,27 @@ export class FtpResponse {
40
47
  * @ko 상태 코드가 400 미만인지 반환하며,
41
48
  * 성공 및 추가 작업이 필요한 응답을 포함합니다.
42
49
  */
43
- isOk(): boolean { return this.status < 400; }
50
+ isOk(): boolean {
51
+ return this.status < 400;
52
+ }
44
53
  /**
45
54
  * Return the response status code.
46
55
  * @zh 返回响应状态码。
47
56
  * @ja レスポンスの状態コードを返します。
48
57
  * @ko 응답 상태 코드를 반환합니다.
49
58
  */
50
- getStatus(): FtpStatus { return this.status; }
59
+ getStatus(): FtpStatus {
60
+ return this.status;
61
+ }
51
62
  /**
52
63
  * Return the server or client error message.
53
64
  * @zh 返回服务端或客户端错误消息。
54
65
  * @ja サーバーまたはクライアントのエラーメッセージを返します。
55
66
  * @ko 서버 또는 클라이언트 오류 메시지를 반환합니다.
56
67
  */
57
- getMessage(): string { return this.message; }
68
+ getMessage(): string {
69
+ return this.message;
70
+ }
58
71
  }
59
72
  /**
60
73
  * FTP response containing a working directory path.
@@ -72,8 +85,11 @@ export class FtpDirectoryResponse extends FtpResponse {
72
85
  */
73
86
  constructor(response: FtpResponse) {
74
87
  super(response.getStatus(), response.getMessage());
75
- this.directory = response.getMessage().match(/"((?:[^"]|"")*)"/)?.[1]
76
- .replace(/""/g, '"') ?? '';
88
+ this.directory =
89
+ response
90
+ .getMessage()
91
+ .match(/"((?:[^"]|"")*)"/)?.[1]
92
+ .replace(/""/g, '"') ?? '';
77
93
  }
78
94
  /**
79
95
  * Return the parsed directory path, or an empty string if none was parsed.
@@ -81,7 +97,9 @@ export class FtpDirectoryResponse extends FtpResponse {
81
97
  * @ja 解析したディレクトリパスを返します。解析できなければ空文字列です。
82
98
  * @ko 파싱한 디렉터리 경로를 반환하며 파싱하지 못했으면 빈 문자열입니다.
83
99
  */
84
- getDirectory(): string { return this.directory; }
100
+ getDirectory(): string {
101
+ return this.directory;
102
+ }
85
103
  }
86
104
  /**
87
105
  * FTP response containing directory entry names.
@@ -107,7 +125,9 @@ export class FtpListingResponse extends FtpResponse {
107
125
  * @ja ディレクトリエントリー名の読み取り専用型の配列を返します。
108
126
  * @ko 디렉터리 항목 이름을 읽기 전용 타입의 배열로 반환합니다.
109
127
  */
110
- getListing(): readonly string[] { return this.listing; }
128
+ getListing(): readonly string[] {
129
+ return this.listing;
130
+ }
111
131
  }
112
132
  function commandPart(value: string): string {
113
133
  if (typeof value !== 'string' || /[\r\n\0]/.test(value)) {
@@ -119,11 +139,17 @@ function response(value: FTPResponse): FtpResponse {
119
139
  return new FtpResponse(value.code, value.message);
120
140
  }
121
141
  function failure(error: unknown): FtpResponse {
122
- if (error instanceof FTPError) return new FtpResponse(error.code, error.message);
142
+ if (error instanceof FTPError) {
143
+ return new FtpResponse(error.code, error.message);
144
+ }
123
145
  const value = error as NodeJS.ErrnoException;
124
- const localFile = [ 'ENOENT', 'EACCES', 'EISDIR', 'ENOTDIR' ].includes(value.code ?? '');
125
- return new FtpResponse(localFile ? FtpStatus.InvalidFile
126
- : FtpStatus.ConnectionClosed, value.message ?? String(error));
146
+ const localFile = [ 'ENOENT', 'EACCES', 'EISDIR', 'ENOTDIR' ].includes(
147
+ value.code ?? '',
148
+ );
149
+ return new FtpResponse(
150
+ localFile ? FtpStatus.InvalidFile : FtpStatus.ConnectionClosed,
151
+ value.message ?? String(error),
152
+ );
127
153
  }
128
154
 
129
155
  /**
@@ -174,23 +200,35 @@ export class Ftp {
174
200
  * @ko FTP 서버에 비동기로 연결하며 기본 포트는 21입니다.
175
201
  * Time.Zero는 연결 제한 시간이 없으며 연결 후 별도로 login해야 합니다.
176
202
  */
177
- connect(server: IpAddress, port = 21, timeout: NetworkTime = Time.Zero):
178
- Promise<FtpResponse> {
179
- if (!(server instanceof IpAddress)) throw new TypeError('Expected IpAddress');
203
+ connect(
204
+ server: IpAddress,
205
+ port = 21,
206
+ timeout: NetworkTime = Time.Zero,
207
+ ): Promise<FtpResponse> {
208
+ if (!(server instanceof IpAddress)) {
209
+ throw new TypeError('Expected IpAddress');
210
+ }
180
211
  uint(port, 65535);
181
212
  const milliseconds = millisecondsOf(timeout);
182
213
  return this.queue.run(async () => {
183
214
  this.client.close();
184
215
  this.client = new Client(0);
185
216
  const client = this.client;
186
- const timer = milliseconds ? setTimeout(() => client.close(), milliseconds)
217
+ const timer = milliseconds
218
+ ? setTimeout(() => client.close(), milliseconds)
187
219
  : undefined;
188
220
  try {
189
221
  return response(await client.connect(server.toString(), port));
190
222
  } catch (error) {
191
- return new FtpResponse(FtpStatus.ConnectionFailed,
192
- error instanceof Error ? error.message : String(error));
193
- } finally { if (timer) clearTimeout(timer); }
223
+ return new FtpResponse(
224
+ FtpStatus.ConnectionFailed,
225
+ error instanceof Error ? error.message : String(error),
226
+ );
227
+ } finally {
228
+ if (timer) {
229
+ clearTimeout(timer);
230
+ }
231
+ }
194
232
  });
195
233
  }
196
234
  /**
@@ -201,9 +239,13 @@ export class Ftp {
201
239
  */
202
240
  disconnect(): Promise<FtpResponse> {
203
241
  return this.queue.run(async () => {
204
- try { return response(await this.client.send('QUIT')); } catch (error) {
242
+ try {
243
+ return response(await this.client.send('QUIT'));
244
+ } catch (error) {
205
245
  return failure(error);
206
- } finally { this.client.close(); }
246
+ } finally {
247
+ this.client.close();
248
+ }
207
249
  });
208
250
  }
209
251
  /**
@@ -212,15 +254,21 @@ export class Ftp {
212
254
  * @ja 未完了の操作を中止し、両方の接続を解放します。
213
255
  * @ko 미완료 작업을 중단하고 두 연결을 모두 해제합니다.
214
256
  */
215
- close(): void { this.client.close(); }
257
+ close(): void {
258
+ this.client.close();
259
+ }
216
260
  /**
217
261
  * Log in asynchronously; omitted arguments use an anonymous account.
218
262
  * @zh 异步登录,省略参数时使用匿名账号。
219
263
  * @ja 非同期にログインします。引数を省略すると匿名アカウントを使います。
220
264
  * @ko 비동기로 로그인하며 인수를 생략하면 익명 계정을 사용합니다.
221
265
  */
222
- login(name = 'anonymous', password = 'user@sfml-dev.org'): Promise<FtpResponse> {
223
- commandPart(name); commandPart(password);
266
+ login(
267
+ name = 'anonymous',
268
+ password = 'user@sfml-dev.org',
269
+ ): Promise<FtpResponse> {
270
+ commandPart(name);
271
+ commandPart(password);
224
272
  return this.run(() => this.client.login(name, password));
225
273
  }
226
274
  /**
@@ -229,7 +277,9 @@ export class Ftp {
229
277
  * @ja NOOP を送信して接続を維持します。
230
278
  * @ko NOOP를 보내 연결을 유지합니다.
231
279
  */
232
- keepAlive(): Promise<FtpResponse> { return this.sendCommand('NOOP'); }
280
+ keepAlive(): Promise<FtpResponse> {
281
+ return this.sendCommand('NOOP');
282
+ }
233
283
  /**
234
284
  * Query the server's current working directory.
235
285
  * @zh 查询服务器当前工作目录。
@@ -261,17 +311,26 @@ export class Ftp {
261
311
  count += chunk.length;
262
312
  if (count > 8 * 1024 * 1024) {
263
313
  callback(new Error('Directory listing exceeds 8 MiB'));
264
- } else { chunks.push(chunk); callback(); }
314
+ } else {
315
+ chunks.push(chunk);
316
+ callback();
317
+ }
265
318
  },
266
319
  });
267
320
  const result = await downloadTo(destination, {
268
321
  command: directory ? `NLST ${directory}` : 'NLST',
269
- remotePath: directory, type: 'list', ftp: this.client.ftp,
322
+ remotePath: directory,
323
+ type: 'list',
324
+ ftp: this.client.ftp,
270
325
  tracker: new ProgressTracker(),
271
326
  });
272
- return new FtpListingResponse(response(result),
273
- Buffer.concat(chunks, count).toString('utf8'));
274
- } catch (error) { return new FtpListingResponse(failure(error)); }
327
+ return new FtpListingResponse(
328
+ response(result),
329
+ Buffer.concat(chunks, count).toString('utf8'),
330
+ );
331
+ } catch (error) {
332
+ return new FtpListingResponse(failure(error));
333
+ }
275
334
  });
276
335
  }
277
336
  /**
@@ -289,7 +348,9 @@ export class Ftp {
289
348
  * @ja サーバーの現在のディレクトリの親に移動します。
290
349
  * @ko 서버의 현재 디렉터리에서 상위 디렉터리로 이동합니다.
291
350
  */
292
- parentDirectory(): Promise<FtpResponse> { return this.sendCommand('CDUP'); }
351
+ parentDirectory(): Promise<FtpResponse> {
352
+ return this.sendCommand('CDUP');
353
+ }
293
354
  /**
294
355
  * Create a remote directory.
295
356
  * @zh 创建远端目录。
@@ -315,7 +376,8 @@ export class Ftp {
315
376
  * @ko 원격 파일 또는 디렉터리 이름을 path에서 newPath로 변경합니다.
316
377
  */
317
378
  renameFile(path: string, newPath: string): Promise<FtpResponse> {
318
- commandPart(path); commandPart(newPath);
379
+ commandPart(path);
380
+ commandPart(newPath);
319
381
  return this.run(() => this.client.rename(path, newPath));
320
382
  }
321
383
  /**
@@ -336,13 +398,19 @@ export class Ftp {
336
398
  * @ko 원본 파일 이름을 유지하여 원격 파일을 로컬 디렉터리 localPath에
337
399
  * 다운로드합니다. 기본적으로 바이너리 전송을 사용합니다.
338
400
  */
339
- download(remoteFile: string, localPath: string,
340
- mode = TransferMode.Binary): Promise<FtpResponse> {
341
- commandPart(remoteFile); uint(mode, 2);
401
+ download(
402
+ remoteFile: string,
403
+ localPath: string,
404
+ mode = TransferMode.Binary,
405
+ ): Promise<FtpResponse> {
406
+ commandPart(remoteFile);
407
+ uint(mode, 2);
342
408
  return this.run(async () => {
343
409
  await this.client.send(`TYPE ${[ 'I', 'A', 'E' ][mode]}`);
344
- return this.client.downloadTo(join(localPath, posix.basename(remoteFile)),
345
- remoteFile);
410
+ return this.client.downloadTo(
411
+ join(localPath, posix.basename(remoteFile)),
412
+ remoteFile,
413
+ );
346
414
  });
347
415
  }
348
416
  /**
@@ -354,13 +422,19 @@ export class Ftp {
354
422
  * @ko 파일 이름을 유지하여 로컬 파일을 원격 디렉터리에 업로드합니다.
355
423
  * append가 true이면 추가하며 기본적으로 덮어씁니다.
356
424
  */
357
- upload(localFile: string, remotePath: string, mode = TransferMode.Binary,
358
- append = false): Promise<FtpResponse> {
359
- commandPart(remotePath); uint(mode, 2);
425
+ upload(
426
+ localFile: string,
427
+ remotePath: string,
428
+ mode = TransferMode.Binary,
429
+ append = false,
430
+ ): Promise<FtpResponse> {
431
+ commandPart(remotePath);
432
+ uint(mode, 2);
360
433
  return this.run(async () => {
361
434
  await this.client.send(`TYPE ${[ 'I', 'A', 'E' ][mode]}`);
362
435
  const target = posix.join(remotePath, basename(localFile));
363
- return append ? this.client.appendFrom(localFile, target)
436
+ return append
437
+ ? this.client.appendFrom(localFile, target)
364
438
  : this.client.uploadFrom(localFile, target);
365
439
  });
366
440
  }
@@ -374,13 +448,21 @@ export class Ftp {
374
448
  * 인수에 줄바꿈이나 널 바이트가 포함되면 안 됩니다.
375
449
  */
376
450
  sendCommand(command: string, parameter = ''): Promise<FtpResponse> {
377
- commandPart(command); commandPart(parameter);
378
- return this.run(() => this.client.sendIgnoringError(
379
- parameter ? `${command} ${parameter}` : command));
451
+ commandPart(command);
452
+ commandPart(parameter);
453
+ return this.run(() =>
454
+ this.client.sendIgnoringError(
455
+ parameter ? `${command} ${parameter}` : command,
456
+ ),
457
+ );
380
458
  }
381
459
  private run(action: () => Promise<FTPResponse>): Promise<FtpResponse> {
382
460
  return this.queue.run(async () => {
383
- try { return response(await action()); } catch (error) { return failure(error); }
461
+ try {
462
+ return response(await action());
463
+ } catch (error) {
464
+ return failure(error);
465
+ }
384
466
  });
385
467
  }
386
468
  }