mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 09:10:35 +08:00
Replace more utilities w/ foxts
This commit is contained in:
parent
47ef19e0f8
commit
a0ef544f66
@ -7,7 +7,7 @@ import { NON_CN_CIDR_INCLUDED_IN_CHNROUTE, RESERVED_IPV4_CIDR } from './constant
|
||||
|
||||
import fs from 'node:fs';
|
||||
import { OUTPUT_INTERNAL_DIR } from './constants/dir';
|
||||
import { asyncWriteToStream } from './lib/async-write-to-stream';
|
||||
import { asyncWriteToStream } from 'foxts/async-write-to-stream';
|
||||
import { mkdirp } from './lib/misc';
|
||||
import { appendArrayInPlace } from './lib/append-array-in-place';
|
||||
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import type { Writable } from 'node:stream';
|
||||
import { once } from 'node:events';
|
||||
|
||||
export function asyncWriteToStream<T>(stream: Writable, chunk: T) {
|
||||
const res = stream.write(chunk);
|
||||
if (!res) {
|
||||
return once(stream, 'drain'); // returns a promise only if needed
|
||||
}
|
||||
}
|
||||
@ -1,12 +0,0 @@
|
||||
/** Packs two 16-bit integers into one 32-bit integer */
|
||||
export const pack = (a: number, b: number): number => (a << 16) | b;
|
||||
|
||||
/** Unpacks two 16-bit integers from one 32-bit integer */
|
||||
export function unpack(value: number, arr: [a: number, b: number] = Array.from(new Array(2).keys()) as any): [a: number, b: number] {
|
||||
arr[0] = (value >> 16) & 0xFFFF;
|
||||
arr[1] = value & 0xFFFF;
|
||||
return arr;
|
||||
}
|
||||
|
||||
export const unpackFirst = (value: number): number => (value >> 16) & 0xFFFF;
|
||||
export const unpackSecond = (value: number): number => value & 0xFFFF;
|
||||
@ -10,7 +10,7 @@ import fs from 'node:fs';
|
||||
import { writeFile } from '../misc';
|
||||
import { fastStringArrayJoin } from 'foxts/fast-string-array-join';
|
||||
import { readFileByLine } from '../fetch-text-by-line';
|
||||
import { asyncWriteToStream } from '../async-write-to-stream';
|
||||
import { asyncWriteToStream } from 'foxts/async-write-to-stream';
|
||||
|
||||
export abstract class RuleOutput<TPreprocessed = unknown> {
|
||||
protected domainTrie = new HostnameSmolTrie(null);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user