xshell 1.3.8 → 1.3.10

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/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Writable, Transform, type Readable, type Duplex, type TransformCallback } from 'node:stream';
1
+ import { Writable, Transform, type Readable, type TransformCallback } from 'node:stream';
2
2
  import util from 'node:util';
3
3
  import './prototype.ts';
4
4
  import './platform.ts';
@@ -11,7 +11,7 @@ export declare function typed_array_to_buffer(view: ArrayBufferView): Buffer<Arr
11
11
  /** 每天在固定时间执行操作
12
12
  - hour: 0 - 23 之间的整数,在这个点执行
13
13
  - action */
14
- export declare function schedule_everyday(hour: number, action: () => Promise<void>): Promise<void>;
14
+ export declare function schedule_everyday(hour: number, minute: number, action: () => Promise<void>): Promise<void>;
15
15
  export declare function log_line(): void;
16
16
  export declare function sha256(data: string | Uint8Array): string;
17
17
  export declare function sha1(data: string | Uint8Array): string;
@@ -31,19 +31,8 @@ export declare namespace inspect {
31
31
  const custom: typeof util.inspect.custom;
32
32
  const defaultOptions: util.InspectOptions;
33
33
  }
34
- /** npm map-stream
35
- filter will reemit the data if cb(err,pass) pass is truthy
36
-
37
- reduce is more tricky
38
- maybe we want to group the reductions or emit progress updates occasionally
39
- the most basic reduce just emits one 'data' event after it has recieved 'end'
40
-
41
- create an event stream and apply function to each .write,
42
- emitting each response as data unless it's an empty callback
43
- */
44
- export declare function map_stream<Out, In = any>(mapper: (obj: In, cb: Function) => any, options?: {
45
- failures?: boolean;
46
- }): Duplex;
34
+ /** 消费一个可读流 */
35
+ export declare function consume_stream(stream: Readable, ignore_error?: boolean): Promise<void>;
47
36
  export declare function stream_to_lines(stream: Readable): AsyncGenerator<string, void, unknown>;
48
37
  export declare class WritableMemoryStream extends Writable {
49
38
  chunks: Uint8Array[];
@@ -65,8 +54,6 @@ export declare class DecoderStream extends Transform {
65
54
  _transform(chunk: Uint8Array, encoding: BufferEncoding, callback: TransformCallback): void;
66
55
  _flush(callback: TransformCallback): void;
67
56
  }
68
- /** 消费一个可读流 */
69
- export declare function consume_stream(stream: Readable, ignore_error?: boolean): Promise<void>;
70
57
  /** 根据 range 生成整数序列 (iterable)
71
58
  - range: 取值为逗号分割的多个可用值或值区间 (不能含有空格),比如:`8321,8322,8300-8310,11000-11999`
72
59
  - reverse?: `false` 在 range 内从后往前生成 */
package/utils.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Stream, Writable, Transform } from 'node:stream';
1
+ import { Writable, Transform } from 'node:stream';
2
2
  import util from 'node:util';
3
3
  import ncrypto from 'node:crypto';
4
4
  import "./prototype.js";
@@ -30,10 +30,10 @@ export function typed_array_to_buffer(view) {
30
30
  /** 每天在固定时间执行操作
31
31
  - hour: 0 - 23 之间的整数,在这个点执行
32
32
  - action */
33
- export async function schedule_everyday(hour, action) {
33
+ export async function schedule_everyday(hour, minute, action) {
34
34
  const now = Date.now();
35
35
  let target = new Date();
36
- target.setHours(hour, 0, 0, 0);
36
+ target.setHours(hour, minute, 0, 0);
37
37
  // 如果目标时间已过,设定为明天的时间
38
38
  if (now > target.getTime())
39
39
  target.setDate(target.getDate() + 1);
@@ -94,120 +94,16 @@ export function colored(str, color, enabled = inspect.defaultOptions.colors) {
94
94
  inspect.defaultOptions = util.inspect.defaultOptions;
95
95
  })(inspect || (inspect = {}));
96
96
  // ------------------------------------ stream
97
- /** npm map-stream
98
- filter will reemit the data if cb(err,pass) pass is truthy
99
-
100
- reduce is more tricky
101
- maybe we want to group the reductions or emit progress updates occasionally
102
- the most basic reduce just emits one 'data' event after it has recieved 'end'
103
-
104
- create an event stream and apply function to each .write,
105
- emitting each response as data unless it's an empty callback
106
- */
107
- export function map_stream(mapper, options) {
108
- options = options || {};
109
- let inputs = 0, outputs = 0, ended = false, paused = false, destroyed = false, last_written = 0, in_next = false;
110
- let stream = Object.assign(new Stream(), {
111
- readable: true,
112
- writable: true,
113
- write(data) {
114
- if (ended)
115
- throw new Error('map stream is not writable');
116
- in_next = false;
117
- inputs++;
118
- try {
119
- // catch sync errors and handle them like async errors
120
- const written = wrapped_mapper(data, inputs, next);
121
- paused = (written === false);
122
- return !paused;
123
- }
124
- catch (err) {
125
- // if the callback has been called syncronously, and the error has occured in an listener, throw it again.
126
- if (in_next)
127
- throw err;
128
- next(err);
129
- return !paused;
130
- }
131
- },
132
- end(data) {
133
- if (ended)
134
- return;
135
- _end(data);
136
- },
137
- destroy() {
138
- ended = destroyed = true;
139
- stream.writable = stream.readable = paused = false;
140
- process.nextTick(function () {
141
- stream.emit('close');
142
- });
143
- },
144
- pause() {
145
- paused = true;
146
- },
147
- resume() {
148
- paused = false;
149
- }
150
- });
151
- let error_event_name = options.failures ? 'failure' : 'error';
152
- // Items that are not ready to be written yet (because they would come out of order) get stuck in a queue for later.
153
- let write_queue = {};
154
- function queue_data(data, number) {
155
- let next_to_write = last_written + 1;
156
- if (number === next_to_write) {
157
- // If it's next, and its not undefined write it
158
- if (data !== undefined)
159
- stream.emit('data', data);
160
- last_written++;
161
- next_to_write++;
162
- }
163
- else
164
- // Otherwise queue it for later.
165
- write_queue[number] = data;
166
- // If the next value is in the queue, write it
167
- if (Object.prototype.hasOwnProperty.call(write_queue, next_to_write)) {
168
- let data_to_write = write_queue[next_to_write];
169
- delete write_queue[next_to_write];
170
- return queue_data(data_to_write, next_to_write);
171
- }
172
- outputs++;
173
- if (inputs === outputs) {
174
- if (paused) {
175
- paused = false;
176
- stream.emit('drain'); // written all the incoming events
177
- }
178
- if (ended)
179
- _end();
180
- }
181
- }
182
- function next(err, data, number) {
183
- if (destroyed)
184
- return;
185
- in_next = true;
186
- if (!err || options.failures)
187
- queue_data(data, number);
188
- if (err)
189
- stream.emit(error_event_name, err);
190
- in_next = false;
191
- }
192
- /** Wrap the mapper function by calling its callback with the order number of the item in the stream. */
193
- function wrapped_mapper(input, number, callback) {
194
- return mapper.call(null, input, function (err, data) {
195
- callback(err, data, number);
196
- });
97
+ /** 消费一个可读流 */
98
+ export async function consume_stream(stream, ignore_error = false) {
99
+ try {
100
+ for await (const chunk of stream)
101
+ ;
197
102
  }
198
- function _end(data) {
199
- // if end was called with args, write it,
200
- ended = true; // write will emit 'end' if ended is true
201
- stream.writable = false;
202
- if (data !== undefined)
203
- return queue_data(data, inputs);
204
- else if (inputs === outputs) { // wait for processing
205
- stream.readable = false;
206
- stream.emit('end');
207
- stream.destroy();
208
- }
103
+ catch (error) {
104
+ if (!ignore_error)
105
+ throw error;
209
106
  }
210
- return stream;
211
107
  }
212
108
  export async function* stream_to_lines(stream) {
213
109
  let buf = '';
@@ -269,17 +165,6 @@ export class DecoderStream extends Transform {
269
165
  callback();
270
166
  }
271
167
  }
272
- /** 消费一个可读流 */
273
- export async function consume_stream(stream, ignore_error = false) {
274
- try {
275
- for await (const chunk of stream)
276
- ;
277
- }
278
- catch (error) {
279
- if (!ignore_error)
280
- throw error;
281
- }
282
- }
283
168
  /** 根据 range 生成整数序列 (iterable)
284
169
  - range: 取值为逗号分割的多个可用值或值区间 (不能含有空格),比如:`8321,8322,8300-8310,11000-11999`
285
170
  - reverse?: `false` 在 range 内从后往前生成 */