@opencode-ai/util 0.0.0-next-16989 → 0.0.0-next-16991

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/dist/bom.d.ts CHANGED
@@ -7,6 +7,14 @@ export declare function split(text: string): {
7
7
  };
8
8
  export declare function join(text: string, bom: boolean): string;
9
9
  export declare function has(content: Uint8Array): boolean;
10
+ export declare function decodeBytes(content: Uint8Array): {
11
+ bom: boolean;
12
+ text: string;
13
+ };
14
+ export declare function syncBytes(content: Uint8Array, bom: boolean): {
15
+ text: string;
16
+ bytes: Uint8Array<ArrayBufferLike> | undefined;
17
+ };
10
18
  export declare const readFile: (fs: FSUtil.Interface, filepath: string) => Effect.Effect<{
11
19
  bom: boolean;
12
20
  text: string;
package/dist/bom.js CHANGED
@@ -14,17 +14,23 @@ export function join(text, bom) {
14
14
  export function has(content) {
15
15
  return content[0] === 0xef && content[1] === 0xbb && content[2] === 0xbf;
16
16
  }
17
+ export function decodeBytes(content) {
18
+ return split(decode(content));
19
+ }
20
+ export function syncBytes(content, bom) {
21
+ const decoded = decode(content);
22
+ const current = split(decoded);
23
+ const canonical = join(current.text, bom);
24
+ return { text: current.text, bytes: decoded === canonical ? undefined : new TextEncoder().encode(canonical) };
25
+ }
17
26
  export const readFile = Effect.fn("Bom.readFile")(function* (fs, filepath) {
18
- return split(decode(yield* fs.readFile(filepath)));
27
+ return decodeBytes(yield* fs.readFile(filepath));
19
28
  });
20
29
  export const syncFile = Effect.fn("Bom.syncFile")(function* (fs, filepath, bom) {
21
- const decoded = decode(yield* fs.readFile(filepath));
22
- const current = split(decoded);
23
- const canonical = join(current.text, bom);
24
- if (decoded === canonical)
25
- return current.text;
26
- yield* fs.writeWithDirs(filepath, canonical);
27
- return current.text;
30
+ const synced = syncBytes(yield* fs.readFile(filepath), bom);
31
+ if (synced.bytes)
32
+ yield* fs.writeWithDirs(filepath, synced.bytes);
33
+ return synced.text;
28
34
  });
29
35
  function decode(content) {
30
36
  return new TextDecoder("utf-8", { ignoreBOM: true }).decode(content);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
3
  "name": "@opencode-ai/util",
4
- "version": "0.0.0-next-16989",
4
+ "version": "0.0.0-next-16991",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "repository": {