瀏覽代碼

Replace more utilities w/ `foxts`

SukkaW 1 年之前
父節點
當前提交
a0ef544f66
共有 4 個文件被更改,包括 2 次插入23 次删除
  1. 1 1
      Build/build-internal-reverse-chn-cidr.ts
  2. 0 9
      Build/lib/async-write-to-stream.ts
  3. 0 12
      Build/lib/bitwise.ts
  4. 1 1
      Build/lib/rules/base.ts

+ 1 - 1
Build/build-internal-reverse-chn-cidr.ts

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

+ 0 - 9
Build/lib/async-write-to-stream.ts

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

+ 0 - 12
Build/lib/bitwise.ts

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

+ 1 - 1
Build/lib/rules/base.ts

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