4
4
// deno-lint-ignore-file prefer-primordials
5
5
6
6
import { TextEncoder } from "ext:deno_web/08_text_encoding.js" ;
7
- import {
8
- intoCallbackAPIWithIntercept ,
9
- MaybeEmpty ,
10
- notImplemented ,
11
- } from "ext:deno_node/_utils.ts" ;
7
+ import { MaybeEmpty , notImplemented } from "ext:deno_node/_utils.ts" ;
12
8
import { pathFromURL } from "ext:deno_web/00_infra.js" ;
13
9
import { promisify } from "ext:deno_node/internal/util.mjs" ;
10
+ import { denoErrorToNodeError } from "ext:deno_node/internal/errors.ts" ;
14
11
15
12
type ReadlinkCallback = (
16
13
err : MaybeEmpty < Error > ,
@@ -69,12 +66,17 @@ export function readlink(
69
66
70
67
const encoding = getEncoding ( optOrCallback ) ;
71
68
72
- intoCallbackAPIWithIntercept < string , Uint8Array | string > (
73
- Deno . readLink ,
74
- ( data : string ) : string | Uint8Array => maybeEncode ( data , encoding ) ,
75
- cb ,
76
- path ,
77
- ) ;
69
+ Deno . readLink ( path ) . then ( ( data : string ) => {
70
+ const res = maybeEncode ( data , encoding ) ;
71
+ if ( cb ) cb ( null , res ) ;
72
+ } , ( err : Error ) => {
73
+ if ( cb ) {
74
+ ( cb as ( e : Error ) => void ) ( denoErrorToNodeError ( err , {
75
+ syscall : "readlink" ,
76
+ path,
77
+ } ) ) ;
78
+ }
79
+ } ) ;
78
80
}
79
81
80
82
export const readlinkPromise = promisify ( readlink ) as (
@@ -88,5 +90,12 @@ export function readlinkSync(
88
90
) : string | Uint8Array {
89
91
path = path instanceof URL ? pathFromURL ( path ) : path ;
90
92
91
- return maybeEncode ( Deno . readLinkSync ( path ) , getEncoding ( opt ) ) ;
93
+ try {
94
+ return maybeEncode ( Deno . readLinkSync ( path ) , getEncoding ( opt ) ) ;
95
+ } catch ( error ) {
96
+ throw denoErrorToNodeError ( error , {
97
+ syscall : "readlink" ,
98
+ path,
99
+ } ) ;
100
+ }
92
101
}
0 commit comments