Replace more utilities w/ foxts

This commit is contained in:
SukkaW 2024-12-12 00:39:50 +08:00
parent 47ef19e0f8
commit a0ef544f66
4 changed files with 2 additions and 23 deletions

View File

@ -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';

View File

@ -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
}
}

View File

@ -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;

View File

@ -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);