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.
- package/README.ja.md +10 -9
- package/README.ko.md +10 -9
- package/README.md +10 -9
- package/README.zh-CN.md +10 -9
- package/binding.gyp +23 -16
- package/dist/audio/effect-processor.js +9 -3
- package/dist/audio/input-sound-file.js +41 -15
- package/dist/audio/listener.js +33 -11
- package/dist/audio/music.js +41 -18
- package/dist/audio/output-sound-file.js +4 -2
- package/dist/audio/playback-device.js +11 -3
- package/dist/audio/sound-buffer-recorder.js +8 -5
- package/dist/audio/sound-buffer.js +40 -17
- package/dist/audio/sound-file-factory.js +21 -9
- package/dist/audio/sound-file-reader.js +21 -7
- package/dist/audio/sound-recorder.js +36 -15
- package/dist/audio/sound-source.js +117 -40
- package/dist/audio/sound-stream.js +14 -5
- package/dist/audio/sound.js +9 -4
- package/dist/audio/value.js +42 -16
- package/dist/graphics/blend-mode.js +2 -1
- package/dist/graphics/boolean-vector.d.ts +1 -2
- package/dist/graphics/boolean-vector.js +19 -9
- package/dist/graphics/color.js +2 -1
- package/dist/graphics/convex-shape.js +7 -3
- package/dist/graphics/font.js +52 -23
- package/dist/graphics/glsl-matrix.js +8 -3
- package/dist/graphics/glsl.js +47 -16
- package/dist/graphics/glyph.js +27 -10
- package/dist/graphics/image.js +30 -14
- package/dist/graphics/rect.js +15 -8
- package/dist/graphics/render-states.js +18 -9
- package/dist/graphics/render-target.js +49 -23
- package/dist/graphics/render-texture.js +24 -12
- package/dist/graphics/render-window.js +6 -3
- package/dist/graphics/shader.js +67 -32
- package/dist/graphics/shape.js +25 -13
- package/dist/graphics/sprite.js +19 -9
- package/dist/graphics/stencil-mode.js +10 -6
- package/dist/graphics/swap.js +2 -1
- package/dist/graphics/text.js +123 -48
- package/dist/graphics/texture.js +48 -24
- package/dist/graphics/transform.js +29 -13
- package/dist/graphics/transformable.js +2 -1
- package/dist/graphics/vertex-array.js +40 -18
- package/dist/graphics/vertex-buffer.js +39 -19
- package/dist/graphics/vertex.js +6 -3
- package/dist/graphics/view.js +30 -14
- package/dist/index.d.ts +4 -4
- package/dist/internal/audio-codec-registry.js +12 -6
- package/dist/internal/audio-input-stream.js +2 -1
- package/dist/internal/audio-music-pump.js +58 -24
- package/dist/internal/audio-recorder-session.js +17 -7
- package/dist/internal/audio-worker-session.js +28 -10
- package/dist/internal/audio-worker.js +40 -21
- package/dist/internal/glsl-value.d.ts +3 -1
- package/dist/internal/glsl-value.js +18 -8
- package/dist/internal/graphics-state.js +29 -15
- package/dist/internal/input-stream.d.ts +3 -1
- package/dist/internal/input-stream.js +16 -7
- package/dist/internal/numeric-properties.js +2 -1
- package/dist/internal/render-states.js +2 -1
- package/dist/internal/scalar.js +22 -13
- package/dist/internal/shaped-glyph.d.ts +3 -1
- package/dist/internal/shaped-glyph.js +12 -4
- package/dist/internal/struct-view.d.ts +3 -1
- package/dist/internal/struct-view.js +3 -1
- package/dist/internal/transformable.js +2 -1
- package/dist/network/common.js +23 -11
- package/dist/network/dns.js +25 -17
- package/dist/network/ftp.js +43 -18
- package/dist/network/http.js +126 -56
- package/dist/network/ip-address.js +50 -25
- package/dist/network/packet.js +63 -25
- package/dist/network/sftp.js +175 -74
- package/dist/network/socket-selector.js +28 -14
- package/dist/network/socket.js +71 -30
- package/dist/network/tcp-listener.js +42 -19
- package/dist/network/tcp-socket.js +111 -53
- package/dist/network/tls-material.js +2 -1
- package/dist/network/udp-socket.js +68 -33
- package/dist/system/angle.js +2 -1
- package/dist/system/clock.js +4 -2
- package/dist/system/err.js +5 -2
- package/dist/system/file-input-stream.js +8 -4
- package/dist/system/input-stream.js +6 -3
- package/dist/system/operators.d.ts +1 -1
- package/dist/system/operators.js +90 -50
- package/dist/system/sleep.js +4 -2
- package/dist/system/time.js +12 -6
- package/dist/system/vector2.js +6 -7
- package/dist/system/vector3.js +11 -6
- package/dist/window/clipboard.js +2 -1
- package/dist/window/context.js +10 -5
- package/dist/window/cursor.js +2 -1
- package/dist/window/event.js +9 -5
- package/dist/window/mouse.js +4 -2
- package/dist/window/video-mode.js +2 -1
- package/dist/window/window.js +19 -12
- package/native/addon.cc +25 -12
- package/native/audio-binding.cc +266 -126
- package/native/audio-codec-binding.cc +147 -77
- package/native/audio-device-binding.cc +76 -49
- package/native/audio-file-binding.cc +116 -67
- package/native/audio-recorder-binding.cc +147 -98
- package/native/audio-recorder.h +1 -1
- package/native/audio-state.h +53 -30
- package/native/audio-stream-binding.cc +148 -94
- package/native/audio-stream.h +5 -4
- package/native/audio-worker-binding.cc +163 -81
- package/native/audio-worker.h +35 -19
- package/native/batch-drawable.cc +29 -16
- package/native/batch-drawable.h +11 -8
- package/native/context-binding.cc +40 -27
- package/native/context-settings.h +15 -8
- package/native/deferred-delete.cc +9 -6
- package/native/deferred-delete.h +7 -8
- package/native/error-stream-binding.cc +42 -28
- package/native/font-binding.cc +89 -48
- package/native/graphics-binding.cc +122 -72
- package/native/graphics-state.h +50 -36
- package/native/image-binding.cc +38 -24
- package/native/image-state.h +26 -18
- package/native/input-binding.cc +42 -27
- package/native/render-window-binding.cc +38 -23
- package/native/shader-binding.cc +115 -50
- package/native/shape-binding.cc +94 -49
- package/native/shape-state.h +18 -9
- package/native/shaped-glyph-storage.h +9 -5
- package/native/stream-binding.cc +143 -117
- package/native/system-binding.cc +17 -12
- package/native/text-binding.cc +68 -35
- package/native/text-state.h +25 -18
- package/native/texture-binding.cc +42 -33
- package/native/texture-resource.h +20 -12
- package/native/time-value.h +3 -1
- package/native/transformable-binding.cc +12 -6
- package/native/transformable-state.h +6 -6
- package/native/value-binding.h +46 -28
- package/native/value-layout.h +10 -10
- package/native/values-binding.cc +29 -23
- package/native/vertex-binding.cc +18 -12
- package/native/vertex-buffer-binding.cc +38 -24
- package/native/vertex-storage.h +2 -2
- package/native/view-data.h +4 -3
- package/native/window-binding.cc +75 -45
- package/native/window-event.h +20 -11
- package/native/window-owner.h +15 -12
- package/package.json +40 -48
- package/src/audio/effect-processor.ts +9 -3
- package/src/audio/input-sound-file.ts +108 -36
- package/src/audio/listener.ts +39 -13
- package/src/audio/music.ts +112 -47
- package/src/audio/output-sound-file.ts +40 -11
- package/src/audio/playback-device.ts +23 -8
- package/src/audio/sound-buffer-recorder.ts +35 -13
- package/src/audio/sound-buffer.ts +166 -58
- package/src/audio/sound-file-factory.ts +127 -49
- package/src/audio/sound-file-reader.ts +49 -15
- package/src/audio/sound-recorder.ts +100 -34
- package/src/audio/sound-source.ts +142 -45
- package/src/audio/sound-stream.ts +15 -5
- package/src/audio/sound.ts +12 -4
- package/src/audio/value.ts +89 -26
- package/src/graphics/blend-mode.ts +3 -1
- package/src/graphics/boolean-vector.ts +56 -26
- package/src/graphics/color.ts +3 -1
- package/src/graphics/convex-shape.ts +10 -3
- package/src/graphics/font.ts +171 -50
- package/src/graphics/glsl-matrix.ts +9 -3
- package/src/graphics/glsl.ts +81 -35
- package/src/graphics/glyph.ts +67 -26
- package/src/graphics/image.ts +119 -45
- package/src/graphics/rect.ts +56 -24
- package/src/graphics/render-states.ts +31 -14
- package/src/graphics/render-target.ts +197 -81
- package/src/graphics/render-texture.ts +36 -12
- package/src/graphics/render-window.ts +9 -3
- package/src/graphics/shader.ts +186 -61
- package/src/graphics/shape.ts +93 -35
- package/src/graphics/sprite.ts +64 -25
- package/src/graphics/stencil-mode.ts +12 -6
- package/src/graphics/swap.ts +3 -2
- package/src/graphics/text.ts +229 -74
- package/src/graphics/texture.ts +180 -61
- package/src/graphics/transform.ts +132 -47
- package/src/graphics/transformable.ts +3 -1
- package/src/graphics/vertex-array.ts +87 -35
- package/src/graphics/vertex-buffer.ts +97 -33
- package/src/graphics/vertex.ts +9 -3
- package/src/graphics/view.ts +59 -21
- package/src/index.ts +101 -23
- package/src/internal/audio-codec-registry.ts +18 -6
- package/src/internal/audio-input-stream.ts +6 -2
- package/src/internal/audio-music-pump.ts +116 -41
- package/src/internal/audio-native.ts +249 -96
- package/src/internal/audio-recorder-session.ts +68 -24
- package/src/internal/audio-worker-session.ts +65 -21
- package/src/internal/audio-worker.ts +85 -41
- package/src/internal/glsl-value.ts +26 -11
- package/src/internal/graphics-state.ts +57 -20
- package/src/internal/input-stream.ts +23 -10
- package/src/internal/native.ts +252 -99
- package/src/internal/numeric-properties.ts +2 -1
- package/src/internal/render-states.ts +3 -1
- package/src/internal/scalar.ts +33 -14
- package/src/internal/shaped-glyph.ts +25 -12
- package/src/internal/struct-view.ts +40 -13
- package/src/internal/transformable.ts +3 -1
- package/src/network/common.ts +35 -11
- package/src/network/dns.ts +95 -38
- package/src/network/ftp.ts +129 -47
- package/src/network/http.ts +232 -77
- package/src/network/ip-address.ts +118 -48
- package/src/network/packet.ts +161 -54
- package/src/network/sftp.ts +498 -168
- package/src/network/socket-selector.ts +66 -26
- package/src/network/socket.ts +133 -46
- package/src/network/tcp-listener.ts +78 -29
- package/src/network/tcp-socket.ts +240 -95
- package/src/network/tls-material.ts +6 -2
- package/src/network/udp-socket.ts +147 -53
- package/src/system/angle.ts +3 -1
- package/src/system/clock.ts +12 -4
- package/src/system/err.ts +5 -2
- package/src/system/file-input-stream.ts +12 -4
- package/src/system/input-stream.ts +9 -3
- package/src/system/operators.ts +290 -115
- package/src/system/sleep.ts +6 -2
- package/src/system/time.ts +18 -6
- package/src/system/timeout-with-predicate.ts +19 -8
- package/src/system/vector2.ts +101 -49
- package/src/system/vector3.ts +85 -36
- package/src/window/clipboard.ts +3 -1
- package/src/window/context.ts +15 -5
- package/src/window/cursor.ts +3 -1
- package/src/window/event.ts +26 -12
- package/src/window/mouse.ts +6 -2
- package/src/window/video-mode.ts +3 -1
- package/src/window/window.ts +119 -37
- package/test/native/audio-probes.cc +74 -36
- package/test/native/deferred-delete-probes.cc +17 -11
- package/test/native/drawable-probes.cc +70 -36
- package/test/native/exception-probes.cc +14 -9
- package/test/native/image-probes.cc +20 -10
- package/test/native/matrix-probes.cc +8 -4
- package/test/native/network-oracle.cc +17 -11
- package/test/native/render-texture-probes.cc +33 -24
- package/test/native/shader-probes.cc +9 -9
- package/test/native/shape-probes.cc +37 -23
- package/test/native/sprite-probes.cc +41 -25
- package/test/native/system-probes.cc +58 -35
- package/test/native/text-probes.cc +77 -44
- package/test/native/texture-probes.cc +43 -26
- package/test/native/time-probes.cc +18 -12
- package/test/native/transform-probes.cc +15 -10
- package/test/native/transformable-probes.cc +23 -17
- package/test/native/value-oracle.h +9 -4
- package/test/native/value-probes.cc +31 -23
- package/test/native/vertex-array-probes.cc +22 -14
- package/test/native/vertex-buffer-probes.cc +28 -17
- package/test/native/view-probes.cc +29 -17
- package/test/native/window-probes.cc +66 -33
- package/tools/ensure-sfml.cjs +9 -0
- package/tools/generate-network-constants.cjs +11 -6
- package/tools/generate-window-constants.cjs +31 -12
- package/docs/README.ja.md +0 -30
- package/docs/README.ko.md +0 -30
- package/docs/README.md +0 -30
- package/docs/README.zh-CN.md +0 -30
- package/docs/api.ja.md +0 -84
- package/docs/api.ko.md +0 -84
- package/docs/api.md +0 -81
- package/docs/api.zh-CN.md +0 -81
- package/docs/audio.ja.md +0 -249
- package/docs/audio.ko.md +0 -251
- package/docs/audio.md +0 -252
- package/docs/audio.zh-CN.md +0 -252
- package/docs/concepts.ja.md +0 -130
- package/docs/concepts.ko.md +0 -130
- package/docs/concepts.md +0 -131
- package/docs/concepts.zh-CN.md +0 -131
- package/docs/development.ja.md +0 -144
- package/docs/development.ko.md +0 -144
- package/docs/development.md +0 -146
- package/docs/development.zh-CN.md +0 -146
- package/docs/getting-started.ja.md +0 -154
- package/docs/getting-started.ko.md +0 -154
- package/docs/getting-started.md +0 -156
- package/docs/getting-started.zh-CN.md +0 -156
- package/docs/graphics.ja.md +0 -256
- package/docs/graphics.ko.md +0 -254
- package/docs/graphics.md +0 -255
- package/docs/graphics.zh-CN.md +0 -257
- package/docs/network.ja.md +0 -214
- package/docs/network.ko.md +0 -216
- package/docs/network.md +0 -218
- package/docs/network.zh-CN.md +0 -218
- package/docs/system.ja.md +0 -169
- package/docs/system.ko.md +0 -171
- package/docs/system.md +0 -173
- package/docs/system.zh-CN.md +0 -173
- package/docs/window.ja.md +0 -138
- package/docs/window.ko.md +0 -140
- package/docs/window.md +0 -141
- package/docs/window.zh-CN.md +0 -141
- package/native/exception-boundary.h +0 -97
- package/native/numeric-fields.h +0 -96
- package/native/shared-handle.h +0 -107
- package/test/tsconfig.json +0 -8
- package/tools/configure-lsp.cjs +0 -23
- package/tools/lib_downloader.cjs +0 -92
- package/tools/lib_downloader_urls.cjs +0 -23
package/dist/network/sftp.js
CHANGED
|
@@ -36,21 +36,27 @@ class SftpResult {
|
|
|
36
36
|
* @ja 結果が Success かどうかを返します。
|
|
37
37
|
* @ko 결과가 Success인지 반환합니다.
|
|
38
38
|
*/
|
|
39
|
-
isOk() {
|
|
39
|
+
isOk() {
|
|
40
|
+
return this.value === constants_1.SftpResultValue.Success;
|
|
41
|
+
}
|
|
40
42
|
/**
|
|
41
43
|
* Return the result code.
|
|
42
44
|
* @zh 返回结果码。
|
|
43
45
|
* @ja 結果コードを返します。
|
|
44
46
|
* @ko 결과 코드를 반환합니다.
|
|
45
47
|
*/
|
|
46
|
-
getValue() {
|
|
48
|
+
getValue() {
|
|
49
|
+
return this.value;
|
|
50
|
+
}
|
|
47
51
|
/**
|
|
48
52
|
* Return the error or status description.
|
|
49
53
|
* @zh 返回错误或状态说明。
|
|
50
54
|
* @ja エラーまたは状態の説明を返します。
|
|
51
55
|
* @ko 오류 또는 상태 설명을 반환합니다.
|
|
52
56
|
*/
|
|
53
|
-
getMessage() {
|
|
57
|
+
getMessage() {
|
|
58
|
+
return this.message;
|
|
59
|
+
}
|
|
54
60
|
}
|
|
55
61
|
/**
|
|
56
62
|
* SFTP result code enumeration.
|
|
@@ -83,7 +89,9 @@ class SftpPathResult extends SftpResult {
|
|
|
83
89
|
* @ja リモートパスを返します。失敗結果では通常、空文字列です。
|
|
84
90
|
* @ko 원격 경로를 반환하며 실패한 결과에서는 보통 빈 문자열입니다.
|
|
85
91
|
*/
|
|
86
|
-
getPath() {
|
|
92
|
+
getPath() {
|
|
93
|
+
return this.path;
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
exports.SftpPathResult = SftpPathResult;
|
|
89
97
|
/**
|
|
@@ -188,7 +196,9 @@ class SftpAttributesResult extends SftpResult {
|
|
|
188
196
|
* @ja この結果が保持する属性オブジェクトを返します。
|
|
189
197
|
* @ko 이 결과가 보유한 속성 객체를 반환합니다.
|
|
190
198
|
*/
|
|
191
|
-
getAttributes() {
|
|
199
|
+
getAttributes() {
|
|
200
|
+
return this.attributes;
|
|
201
|
+
}
|
|
192
202
|
}
|
|
193
203
|
exports.SftpAttributesResult = SftpAttributesResult;
|
|
194
204
|
/**
|
|
@@ -214,7 +224,9 @@ class SftpListingResult extends SftpResult {
|
|
|
214
224
|
* @ja この結果が保持するディレクトリエントリー一覧を返します。
|
|
215
225
|
* @ko 이 결과가 보유한 디렉터리 항목 목록을 반환합니다.
|
|
216
226
|
*/
|
|
217
|
-
getListing() {
|
|
227
|
+
getListing() {
|
|
228
|
+
return this.listing;
|
|
229
|
+
}
|
|
218
230
|
}
|
|
219
231
|
exports.SftpListingResult = SftpListingResult;
|
|
220
232
|
class OperationError extends Error {
|
|
@@ -225,50 +237,82 @@ class OperationError extends Error {
|
|
|
225
237
|
}
|
|
226
238
|
const ok = () => new SftpResult(constants_1.SftpResultValue.Success);
|
|
227
239
|
function position(value) {
|
|
228
|
-
if (typeof value !== 'bigint' ||
|
|
240
|
+
if (typeof value !== 'bigint' ||
|
|
241
|
+
value < 0n ||
|
|
229
242
|
value > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
230
243
|
throw new RangeError('ssh2 file offsets must be exact integers up to 2^53 - 1');
|
|
231
244
|
}
|
|
232
245
|
return Number(value);
|
|
233
246
|
}
|
|
234
247
|
function result(error) {
|
|
235
|
-
if (error instanceof OperationError)
|
|
248
|
+
if (error instanceof OperationError) {
|
|
236
249
|
return new SftpResult(error.value, error.message);
|
|
250
|
+
}
|
|
237
251
|
const err = error;
|
|
238
|
-
const statuses = [
|
|
239
|
-
constants_1.SftpResultValue.
|
|
240
|
-
constants_1.SftpResultValue.
|
|
241
|
-
constants_1.SftpResultValue.
|
|
242
|
-
constants_1.SftpResultValue.
|
|
243
|
-
constants_1.SftpResultValue.
|
|
244
|
-
constants_1.SftpResultValue.
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
252
|
+
const statuses = [
|
|
253
|
+
constants_1.SftpResultValue.Success,
|
|
254
|
+
constants_1.SftpResultValue.EndOfFile,
|
|
255
|
+
constants_1.SftpResultValue.NoSuchFile,
|
|
256
|
+
constants_1.SftpResultValue.PermissionDenied,
|
|
257
|
+
constants_1.SftpResultValue.Failure,
|
|
258
|
+
constants_1.SftpResultValue.BadMessage,
|
|
259
|
+
constants_1.SftpResultValue.NoConnection,
|
|
260
|
+
constants_1.SftpResultValue.ConnectionLost,
|
|
261
|
+
constants_1.SftpResultValue.OperationUnsupported,
|
|
262
|
+
constants_1.SftpResultValue.InvalidHandle,
|
|
263
|
+
constants_1.SftpResultValue.NoSuchPath,
|
|
264
|
+
constants_1.SftpResultValue.FileAlreadyExists,
|
|
265
|
+
constants_1.SftpResultValue.WriteProtect,
|
|
266
|
+
constants_1.SftpResultValue.NoMedia,
|
|
267
|
+
constants_1.SftpResultValue.NoSpaceOnFileSystem,
|
|
268
|
+
constants_1.SftpResultValue.QuotaExceeded,
|
|
269
|
+
constants_1.SftpResultValue.UnknownPrincipal,
|
|
270
|
+
constants_1.SftpResultValue.LockConflict,
|
|
271
|
+
constants_1.SftpResultValue.DirectoryNotEmpty,
|
|
272
|
+
constants_1.SftpResultValue.NotADirectory,
|
|
273
|
+
constants_1.SftpResultValue.InvalidFilename,
|
|
274
|
+
constants_1.SftpResultValue.LinkLoop,
|
|
275
|
+
];
|
|
276
|
+
const code = typeof err.code === 'number'
|
|
277
|
+
? statuses[err.code]
|
|
278
|
+
: err.code === 'ECONNREFUSED'
|
|
279
|
+
? constants_1.SftpResultValue.Refused
|
|
280
|
+
: err.level === 'client-authentication'
|
|
281
|
+
? constants_1.SftpResultValue.AuthenticationFailed
|
|
248
282
|
: undefined;
|
|
249
283
|
return new SftpResult(code ?? constants_1.SftpResultValue.Error, err.message ?? String(error));
|
|
250
284
|
}
|
|
251
285
|
function attributes(path, input) {
|
|
252
286
|
const integer = (value) => {
|
|
253
|
-
if (value === undefined)
|
|
287
|
+
if (value === undefined) {
|
|
254
288
|
return undefined;
|
|
289
|
+
}
|
|
255
290
|
if (!Number.isSafeInteger(value) || value < 0) {
|
|
256
291
|
throw new RangeError('SFTP attribute exceeds exact integer range');
|
|
257
292
|
}
|
|
258
293
|
return BigInt(value);
|
|
259
294
|
};
|
|
260
295
|
const types = {
|
|
261
|
-
8: FileType.Regular,
|
|
262
|
-
|
|
296
|
+
8: FileType.Regular,
|
|
297
|
+
4: FileType.Directory,
|
|
298
|
+
10: FileType.Symlink,
|
|
299
|
+
6: FileType.Block,
|
|
300
|
+
2: FileType.Character,
|
|
301
|
+
1: FileType.Fifo,
|
|
302
|
+
12: FileType.Socket,
|
|
263
303
|
};
|
|
264
|
-
return {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
304
|
+
return {
|
|
305
|
+
path,
|
|
306
|
+
type: input.mode === undefined
|
|
307
|
+
? undefined
|
|
308
|
+
: (types[Math.floor(input.mode / 4096) % 16] ?? FileType.Unknown),
|
|
309
|
+
size: integer(input.size),
|
|
310
|
+
permissions: input.mode === undefined ? undefined : input.mode % 4096,
|
|
311
|
+
userId: integer(input.uid),
|
|
312
|
+
groupId: integer(input.gid),
|
|
270
313
|
accessTime: input.atime === undefined ? undefined : new Date(input.atime * 1000),
|
|
271
|
-
modificationTime: input.mtime === undefined ? undefined : new Date(input.mtime * 1000)
|
|
314
|
+
modificationTime: input.mtime === undefined ? undefined : new Date(input.mtime * 1000),
|
|
315
|
+
};
|
|
272
316
|
}
|
|
273
317
|
/**
|
|
274
318
|
* Asynchronous SFTP client based on ssh2; file operations run in call order.
|
|
@@ -303,8 +347,9 @@ class Sftp {
|
|
|
303
347
|
* getSessionInfo로 호스트 지문을 검증할 수 있습니다.
|
|
304
348
|
*/
|
|
305
349
|
connect(server, port = 22, timeout = time_1.Time.Zero) {
|
|
306
|
-
if (!(server instanceof ip_address_1.IpAddress))
|
|
350
|
+
if (!(server instanceof ip_address_1.IpAddress)) {
|
|
307
351
|
throw new TypeError('Expected IpAddress');
|
|
352
|
+
}
|
|
308
353
|
(0, common_1.uint)(port, 65535);
|
|
309
354
|
return this.queue.run(async () => {
|
|
310
355
|
this.close();
|
|
@@ -315,20 +360,23 @@ class Sftp {
|
|
|
315
360
|
this.transport = transport;
|
|
316
361
|
transport.on('data', () => this.progress());
|
|
317
362
|
transport.on('error', error => {
|
|
318
|
-
if (this.transport !== transport)
|
|
363
|
+
if (this.transport !== transport) {
|
|
319
364
|
return;
|
|
365
|
+
}
|
|
320
366
|
this.failure = error;
|
|
321
367
|
this.events.emit('change');
|
|
322
368
|
});
|
|
323
369
|
client.on('error', error => {
|
|
324
|
-
if (this.client !== client)
|
|
370
|
+
if (this.client !== client) {
|
|
325
371
|
return;
|
|
372
|
+
}
|
|
326
373
|
this.failure = error;
|
|
327
374
|
this.events.emit('change');
|
|
328
375
|
});
|
|
329
376
|
client.on('close', () => {
|
|
330
|
-
if (this.client !== client)
|
|
377
|
+
if (this.client !== client) {
|
|
331
378
|
return;
|
|
379
|
+
}
|
|
332
380
|
this.client = undefined;
|
|
333
381
|
this.sftp = undefined;
|
|
334
382
|
this.nextAuth = undefined;
|
|
@@ -345,13 +393,20 @@ class Sftp {
|
|
|
345
393
|
try {
|
|
346
394
|
await this.timed(timeout, async () => {
|
|
347
395
|
transport.connect(port, server.toString());
|
|
348
|
-
client.connect({
|
|
349
|
-
|
|
396
|
+
client.connect({
|
|
397
|
+
sock: transport,
|
|
398
|
+
username: '',
|
|
399
|
+
readyTimeout: 0,
|
|
400
|
+
hostVerifier: (key) => {
|
|
401
|
+
this.key = Buffer.from(key);
|
|
402
|
+
return true;
|
|
403
|
+
},
|
|
350
404
|
authHandler: (_methods, _partial, next) => {
|
|
351
405
|
this.nextAuth = next;
|
|
352
406
|
this.authRound++;
|
|
353
407
|
this.events.emit('change');
|
|
354
|
-
},
|
|
408
|
+
},
|
|
409
|
+
});
|
|
355
410
|
await this.state(() => !!this.nextAuth);
|
|
356
411
|
});
|
|
357
412
|
return ok();
|
|
@@ -373,7 +428,8 @@ class Sftp {
|
|
|
373
428
|
*/
|
|
374
429
|
disconnect(timeout = time_1.Time.Zero) {
|
|
375
430
|
(0, common_1.millisecondsOf)(timeout instanceof timeout_with_predicate_1.TimeoutWithPredicate
|
|
376
|
-
? timeout.getPeriod()
|
|
431
|
+
? timeout.getPeriod()
|
|
432
|
+
: timeout);
|
|
377
433
|
this.close();
|
|
378
434
|
return Promise.resolve(ok());
|
|
379
435
|
}
|
|
@@ -397,31 +453,44 @@ class Sftp {
|
|
|
397
453
|
this.events.emit('change');
|
|
398
454
|
}
|
|
399
455
|
login(name, passwordOrPublic, keyOrTimeout, passphrase = '', timeout = time_1.Time.Zero) {
|
|
400
|
-
const publicKey = typeof keyOrTimeout === 'string' ||
|
|
401
|
-
|
|
456
|
+
const publicKey = typeof keyOrTimeout === 'string' ||
|
|
457
|
+
keyOrTimeout instanceof Uint8Array;
|
|
458
|
+
const duration = publicKey
|
|
459
|
+
? timeout
|
|
460
|
+
: (keyOrTimeout ?? time_1.Time.Zero);
|
|
402
461
|
let method;
|
|
403
462
|
if (publicKey) {
|
|
404
463
|
const key = ssh2_1.utils.parseKey(typeof keyOrTimeout === 'string'
|
|
405
|
-
? keyOrTimeout
|
|
406
|
-
|
|
464
|
+
? keyOrTimeout
|
|
465
|
+
: (0, common_1.bytes)(keyOrTimeout), passphrase);
|
|
466
|
+
if (key instanceof Error) {
|
|
407
467
|
return Promise.resolve(result(key));
|
|
468
|
+
}
|
|
408
469
|
const advertised = ssh2_1.utils.parseKey(typeof passwordOrPublic === 'string'
|
|
409
|
-
? passwordOrPublic
|
|
410
|
-
|
|
470
|
+
? passwordOrPublic
|
|
471
|
+
: (0, common_1.bytes)(passwordOrPublic));
|
|
472
|
+
if (advertised instanceof Error ||
|
|
473
|
+
!key.getPublicSSH().equals(advertised.getPublicSSH())) {
|
|
411
474
|
return Promise.resolve(new SftpResult(constants_1.SftpResultValue.PublicKeyUnverified, 'Public and private keys do not match'));
|
|
412
475
|
}
|
|
413
476
|
method = { type: 'publickey', username: name, key };
|
|
414
477
|
}
|
|
415
478
|
else {
|
|
416
|
-
if (typeof passwordOrPublic !== 'string')
|
|
479
|
+
if (typeof passwordOrPublic !== 'string') {
|
|
417
480
|
throw new TypeError('Expected password');
|
|
418
|
-
|
|
481
|
+
}
|
|
482
|
+
method = {
|
|
483
|
+
type: 'password',
|
|
484
|
+
username: name,
|
|
485
|
+
password: passwordOrPublic,
|
|
486
|
+
};
|
|
419
487
|
}
|
|
420
488
|
return this.queue.run(async () => {
|
|
421
489
|
try {
|
|
422
490
|
await this.timed(duration, async () => {
|
|
423
|
-
if (!this.nextAuth)
|
|
491
|
+
if (!this.nextAuth) {
|
|
424
492
|
throw new OperationError(constants_1.SftpResultValue.Disconnected, 'Connect before login');
|
|
493
|
+
}
|
|
425
494
|
const next = this.nextAuth;
|
|
426
495
|
this.nextAuth = undefined;
|
|
427
496
|
const round = this.authRound;
|
|
@@ -449,27 +518,37 @@ class Sftp {
|
|
|
449
518
|
* 핸드셰이크 정보가 준비되지 않았으면 undefined입니다.
|
|
450
519
|
*/
|
|
451
520
|
getSessionInfo() {
|
|
452
|
-
if (!this.key || !this.algorithms)
|
|
521
|
+
if (!this.key || !this.algorithms) {
|
|
453
522
|
return undefined;
|
|
523
|
+
}
|
|
454
524
|
const { key, algorithms: a } = this;
|
|
455
525
|
const keyName = key.length >= 4
|
|
456
|
-
? key.toString('ascii', 4, 4 + key.readUInt32BE())
|
|
526
|
+
? key.toString('ascii', 4, 4 + key.readUInt32BE())
|
|
527
|
+
: '';
|
|
457
528
|
const names = {
|
|
458
|
-
'ssh-rsa': constants_1.SftpHostKeyType.Rsa,
|
|
529
|
+
'ssh-rsa': constants_1.SftpHostKeyType.Rsa,
|
|
530
|
+
'ssh-dss': constants_1.SftpHostKeyType.Dsa,
|
|
459
531
|
'ecdsa-sha2-nistp256': constants_1.SftpHostKeyType.Ecdsa256,
|
|
460
532
|
'ecdsa-sha2-nistp384': constants_1.SftpHostKeyType.Ecdsa384,
|
|
461
533
|
'ecdsa-sha2-nistp521': constants_1.SftpHostKeyType.Ecdsa521,
|
|
462
534
|
'ssh-ed25519': constants_1.SftpHostKeyType.Ed25519,
|
|
463
535
|
};
|
|
464
|
-
return {
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
536
|
+
return {
|
|
537
|
+
hostKey: {
|
|
538
|
+
type: names[keyName] ?? constants_1.SftpHostKeyType.Unknown,
|
|
539
|
+
data: Uint8Array.from(key),
|
|
540
|
+
sha1: (0, node_crypto_1.createHash)('sha1').update(key).digest(),
|
|
541
|
+
sha256: (0, node_crypto_1.createHash)('sha256').update(key).digest(),
|
|
542
|
+
},
|
|
543
|
+
keyExchangeAlgorithm: a.kex,
|
|
544
|
+
hostKeyAlgorithm: a.serverHostKey,
|
|
468
545
|
clientToServerEncryptionAlgorithm: a.cs.cipher,
|
|
469
546
|
serverToClientEncryptionAlgorithm: a.sc.cipher,
|
|
470
|
-
clientToServerMacAlgorithm: a.cs.mac,
|
|
547
|
+
clientToServerMacAlgorithm: a.cs.mac,
|
|
548
|
+
serverToClientMacAlgorithm: a.sc.mac,
|
|
471
549
|
clientToServerCompressionAlgorithm: a.cs.compress,
|
|
472
|
-
serverToClientCompressionAlgorithm: a.sc.compress
|
|
550
|
+
serverToClientCompressionAlgorithm: a.sc.compress,
|
|
551
|
+
};
|
|
473
552
|
}
|
|
474
553
|
/**
|
|
475
554
|
* Ask the server to resolve a canonical absolute path.
|
|
@@ -509,7 +588,9 @@ class Sftp {
|
|
|
509
588
|
getAttributes(path, followLinks = true, timeout = time_1.Time.Zero) {
|
|
510
589
|
return this.queue.run(async () => {
|
|
511
590
|
try {
|
|
512
|
-
const data = await this.timed(timeout, () => this.rpc(done => (followLinks
|
|
591
|
+
const data = await this.timed(timeout, () => this.rpc(done => (followLinks
|
|
592
|
+
? this.channel().stat(path, done)
|
|
593
|
+
: this.channel().lstat(path, done))));
|
|
513
594
|
return new SftpAttributesResult(ok(), attributes(path, data));
|
|
514
595
|
}
|
|
515
596
|
catch (error) {
|
|
@@ -592,22 +673,26 @@ class Sftp {
|
|
|
592
673
|
const handle = await this.rpc(done => channel.open(path, 'r', done));
|
|
593
674
|
try {
|
|
594
675
|
for (;;) {
|
|
595
|
-
if (this.sftp !== channel)
|
|
676
|
+
if (this.sftp !== channel) {
|
|
596
677
|
throw new OperationError(constants_1.SftpResultValue.Disconnected, 'Transfer ended');
|
|
678
|
+
}
|
|
597
679
|
const data = Buffer.allocUnsafe(65536);
|
|
598
680
|
const start = at;
|
|
599
681
|
const count = await this.rpc(done => channel.read(handle, data, 0, data.length, start, (error, count) => done(error, count)));
|
|
600
682
|
at = position(BigInt(at) + BigInt(count));
|
|
601
683
|
const more = await callback(data.subarray(0, count));
|
|
602
|
-
if (typeof more !== 'boolean')
|
|
684
|
+
if (typeof more !== 'boolean') {
|
|
603
685
|
throw new TypeError('Expected callback boolean');
|
|
604
|
-
|
|
686
|
+
}
|
|
687
|
+
if (!more || !count) {
|
|
605
688
|
break;
|
|
689
|
+
}
|
|
606
690
|
}
|
|
607
691
|
}
|
|
608
692
|
finally {
|
|
609
|
-
if (this.sftp === channel)
|
|
693
|
+
if (this.sftp === channel) {
|
|
610
694
|
await this.rpc(done => channel.close(handle, done));
|
|
695
|
+
}
|
|
611
696
|
}
|
|
612
697
|
});
|
|
613
698
|
}
|
|
@@ -659,8 +744,9 @@ class Sftp {
|
|
|
659
744
|
const data = Buffer.allocUnsafe(65536);
|
|
660
745
|
const chunk = { data, size: data.length };
|
|
661
746
|
const more = await callback(chunk);
|
|
662
|
-
if (this.sftp !== channel)
|
|
747
|
+
if (this.sftp !== channel) {
|
|
663
748
|
throw new OperationError(constants_1.SftpResultValue.Disconnected, 'Transfer ended');
|
|
749
|
+
}
|
|
664
750
|
if (typeof more !== 'boolean' || chunk.data !== data) {
|
|
665
751
|
throw new TypeError('Fill the provided upload buffer and return boolean');
|
|
666
752
|
}
|
|
@@ -670,13 +756,15 @@ class Sftp {
|
|
|
670
756
|
await this.rpc(done => channel.write(handle, data, 0, chunk.size, start, done));
|
|
671
757
|
at = position(BigInt(at) + BigInt(chunk.size));
|
|
672
758
|
}
|
|
673
|
-
if (!more || !chunk.size)
|
|
759
|
+
if (!more || !chunk.size) {
|
|
674
760
|
break;
|
|
761
|
+
}
|
|
675
762
|
}
|
|
676
763
|
}
|
|
677
764
|
finally {
|
|
678
|
-
if (this.sftp === channel)
|
|
765
|
+
if (this.sftp === channel) {
|
|
679
766
|
await this.rpc(done => channel.close(handle, done));
|
|
767
|
+
}
|
|
680
768
|
}
|
|
681
769
|
});
|
|
682
770
|
}
|
|
@@ -694,31 +782,37 @@ class Sftp {
|
|
|
694
782
|
}
|
|
695
783
|
/** 返回当前 SFTP 通道,未认证时抛出错误。 */
|
|
696
784
|
channel() {
|
|
697
|
-
if (!this.sftp)
|
|
785
|
+
if (!this.sftp) {
|
|
698
786
|
throw new OperationError(constants_1.SftpResultValue.Disconnected, 'SFTP is not authenticated');
|
|
787
|
+
}
|
|
699
788
|
return this.sftp;
|
|
700
789
|
}
|
|
701
790
|
/** 等待 check 为 true、故障出现或连接关闭。 */
|
|
702
791
|
async state(check) {
|
|
703
792
|
await (0, common_1.waitFor)(this.events, () => check() || !!this.failure || !this.client);
|
|
704
|
-
if (this.failure)
|
|
793
|
+
if (this.failure) {
|
|
705
794
|
throw this.failure;
|
|
706
|
-
|
|
795
|
+
}
|
|
796
|
+
if (!this.client) {
|
|
707
797
|
throw new OperationError(constants_1.SftpResultValue.Disconnected, 'SSH connection closed');
|
|
798
|
+
}
|
|
708
799
|
}
|
|
709
800
|
/** 包装 ssh2 回调为 Promise,连接关闭时自动拒绝。 */
|
|
710
801
|
rpc(call) {
|
|
711
802
|
const client = this.client;
|
|
712
|
-
if (!client)
|
|
803
|
+
if (!client) {
|
|
713
804
|
return Promise.reject(new OperationError(constants_1.SftpResultValue.Disconnected, 'SSH connection closed'));
|
|
805
|
+
}
|
|
714
806
|
return new Promise((resolve, reject) => {
|
|
715
807
|
const done = (error, value) => {
|
|
716
808
|
client.off('close', closed);
|
|
717
809
|
this.progress();
|
|
718
|
-
if (error)
|
|
810
|
+
if (error) {
|
|
719
811
|
reject(error);
|
|
720
|
-
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
721
814
|
resolve(value);
|
|
815
|
+
}
|
|
722
816
|
};
|
|
723
817
|
function closed() {
|
|
724
818
|
done(new OperationError(constants_1.SftpResultValue.Disconnected, 'SSH connection closed'));
|
|
@@ -734,14 +828,17 @@ class Sftp {
|
|
|
734
828
|
}
|
|
735
829
|
/** 运行操作并应用超时;每次收到数据或 RPC 完成时重置计时。 */
|
|
736
830
|
async timed(timeout, action) {
|
|
737
|
-
const config = timeout instanceof timeout_with_predicate_1.TimeoutWithPredicate
|
|
831
|
+
const config = timeout instanceof timeout_with_predicate_1.TimeoutWithPredicate
|
|
832
|
+
? timeout
|
|
738
833
|
: new timeout_with_predicate_1.TimeoutWithPredicate(timeout);
|
|
739
834
|
const period = (0, common_1.millisecondsOf)(config.getPeriod());
|
|
740
835
|
let timer;
|
|
741
836
|
let stopped = false;
|
|
742
837
|
let timedOut = false;
|
|
743
838
|
let rejectTimeout;
|
|
744
|
-
const deadline = new Promise((_resolve, reject) => {
|
|
839
|
+
const deadline = new Promise((_resolve, reject) => {
|
|
840
|
+
rejectTimeout = reject;
|
|
841
|
+
});
|
|
745
842
|
const client = this.client;
|
|
746
843
|
const closed = () => {
|
|
747
844
|
if (client !== this.client && !timedOut) {
|
|
@@ -750,10 +847,12 @@ class Sftp {
|
|
|
750
847
|
};
|
|
751
848
|
this.events.on('change', closed);
|
|
752
849
|
const touch = () => {
|
|
753
|
-
if (stopped || !period)
|
|
850
|
+
if (stopped || !period) {
|
|
754
851
|
return;
|
|
755
|
-
|
|
852
|
+
}
|
|
853
|
+
if (timer) {
|
|
756
854
|
clearTimeout(timer);
|
|
855
|
+
}
|
|
757
856
|
timer = setTimeout(() => {
|
|
758
857
|
try {
|
|
759
858
|
if (config.getPredicate()()) {
|
|
@@ -775,14 +874,16 @@ class Sftp {
|
|
|
775
874
|
try {
|
|
776
875
|
const operation = action();
|
|
777
876
|
const value = await Promise.race([operation, deadline]);
|
|
778
|
-
if (timedOut)
|
|
877
|
+
if (timedOut) {
|
|
779
878
|
throw new OperationError(constants_1.SftpResultValue.Timeout, 'SFTP operation timed out');
|
|
879
|
+
}
|
|
780
880
|
return value;
|
|
781
881
|
}
|
|
782
882
|
finally {
|
|
783
883
|
stopped = true;
|
|
784
|
-
if (timer)
|
|
884
|
+
if (timer) {
|
|
785
885
|
clearTimeout(timer);
|
|
886
|
+
}
|
|
786
887
|
this.events.off('change', closed);
|
|
787
888
|
this.progress = () => { };
|
|
788
889
|
}
|
|
@@ -48,8 +48,9 @@ class SocketSelector {
|
|
|
48
48
|
this.entries = new Map();
|
|
49
49
|
this.ready = new Map();
|
|
50
50
|
this.waiting = false;
|
|
51
|
-
if (source !== undefined)
|
|
51
|
+
if (source !== undefined) {
|
|
52
52
|
this.assign(source);
|
|
53
|
+
}
|
|
53
54
|
}
|
|
54
55
|
/**
|
|
55
56
|
* Copy another selector's registrations and snapshot, returning this.
|
|
@@ -64,10 +65,12 @@ class SocketSelector {
|
|
|
64
65
|
if (!(source instanceof SocketSelector)) {
|
|
65
66
|
throw new TypeError('Expected a SocketSelector');
|
|
66
67
|
}
|
|
67
|
-
if (source === this)
|
|
68
|
+
if (source === this) {
|
|
68
69
|
return this;
|
|
69
|
-
|
|
70
|
+
}
|
|
71
|
+
if (this.waiting) {
|
|
70
72
|
throw new Error('Finish the pending wait before assigning');
|
|
73
|
+
}
|
|
71
74
|
this.entries = new Map(source.entries);
|
|
72
75
|
this.ready = new Map(source.ready);
|
|
73
76
|
return this;
|
|
@@ -82,16 +85,19 @@ class SocketSelector {
|
|
|
82
85
|
* 반환하며 콜백은 명시적으로 dispatch해야 합니다.
|
|
83
86
|
*/
|
|
84
87
|
add(socket, readiness = ReadinessType.Receive, callback) {
|
|
85
|
-
if (!(socket instanceof socket_1.Socket))
|
|
88
|
+
if (!(socket instanceof socket_1.Socket)) {
|
|
86
89
|
throw new TypeError('Expected a Socket');
|
|
90
|
+
}
|
|
87
91
|
(0, common_1.uint)(readiness, 3);
|
|
88
|
-
if (!readiness)
|
|
92
|
+
if (!readiness) {
|
|
89
93
|
throw new RangeError('Expected Receive and/or Send');
|
|
94
|
+
}
|
|
90
95
|
if (callback !== undefined && typeof callback !== 'function') {
|
|
91
96
|
throw new TypeError('Expected a callback');
|
|
92
97
|
}
|
|
93
|
-
if (!socket[socket_1.socketAlive]() || this.entries.has(socket))
|
|
98
|
+
if (!socket[socket_1.socketAlive]() || this.entries.has(socket)) {
|
|
94
99
|
return false;
|
|
100
|
+
}
|
|
95
101
|
this.entries.set(socket, { mask: readiness, callback });
|
|
96
102
|
this.cancel?.abort();
|
|
97
103
|
return true;
|
|
@@ -137,18 +143,21 @@ class SocketSelector {
|
|
|
137
143
|
*/
|
|
138
144
|
async wait(timeout = time_1.Time.Zero) {
|
|
139
145
|
const milliseconds = (0, common_1.millisecondsOf)(timeout);
|
|
140
|
-
if (this.waiting)
|
|
146
|
+
if (this.waiting) {
|
|
141
147
|
throw new Error('A selector wait is already pending');
|
|
148
|
+
}
|
|
142
149
|
this.ready.clear();
|
|
143
|
-
if (!this.entries.size)
|
|
150
|
+
if (!this.entries.size) {
|
|
144
151
|
return false;
|
|
152
|
+
}
|
|
145
153
|
this.waiting = true;
|
|
146
154
|
this.cancel = new AbortController();
|
|
147
155
|
const events = new node_events_1.EventEmitter();
|
|
148
156
|
const notify = () => events.emit('change');
|
|
149
157
|
const sockets = [...this.entries.keys()];
|
|
150
|
-
for (const socket of sockets)
|
|
158
|
+
for (const socket of sockets) {
|
|
151
159
|
socket[socket_1.socketEvents].on('change', notify);
|
|
160
|
+
}
|
|
152
161
|
try {
|
|
153
162
|
await (0, common_1.waitFor)(events, () => {
|
|
154
163
|
let count = 0;
|
|
@@ -162,14 +171,15 @@ class SocketSelector {
|
|
|
162
171
|
this.ready.delete(socket);
|
|
163
172
|
}
|
|
164
173
|
}
|
|
165
|
-
return count !== 0 ||
|
|
166
|
-
.every(socket => !socket[socket_1.socketAlive]());
|
|
174
|
+
return (count !== 0 ||
|
|
175
|
+
[...this.entries.keys()].every(socket => !socket[socket_1.socketAlive]()));
|
|
167
176
|
}, milliseconds, this.cancel.signal);
|
|
168
177
|
return this.ready.size > 0;
|
|
169
178
|
}
|
|
170
179
|
finally {
|
|
171
|
-
for (const socket of sockets)
|
|
180
|
+
for (const socket of sockets) {
|
|
172
181
|
socket[socket_1.socketEvents].off('change', notify);
|
|
182
|
+
}
|
|
173
183
|
this.waiting = false;
|
|
174
184
|
this.cancel = undefined;
|
|
175
185
|
}
|
|
@@ -192,9 +202,13 @@ class SocketSelector {
|
|
|
192
202
|
* @ko 최근 wait에서 준비된 항목의 등록된 콜백을 동기적으로 호출합니다.
|
|
193
203
|
*/
|
|
194
204
|
dispatchReadyCallbacks() {
|
|
195
|
-
const callbacks = [...this.ready].map(([socket, mask]) => ({
|
|
196
|
-
|
|
205
|
+
const callbacks = [...this.ready].map(([socket, mask]) => ({
|
|
206
|
+
callback: this.entries.get(socket)?.callback,
|
|
207
|
+
mask,
|
|
208
|
+
}));
|
|
209
|
+
for (const { callback, mask } of callbacks) {
|
|
197
210
|
callback?.(mask);
|
|
211
|
+
}
|
|
198
212
|
}
|
|
199
213
|
}
|
|
200
214
|
/**
|