1
1
import type { Denops } from "https://deno.land/x/denops_core@v3.2.0/mod.ts" ;
2
2
import * as fs from "https://deno.land/std@0.160.0/fs/mod.ts" ;
3
- import * as hash from "https://deno.land/std@0.160.0/hash/mod.ts" ;
4
3
import * as path from "https://deno.land/std@0.160.0/path/mod.ts" ;
5
4
import { execute } from "./execute.ts" ;
6
5
@@ -39,7 +38,7 @@ async function ensureLocalFile(url: URL): Promise<string> {
39
38
return path . fromFileUrl ( url ) ;
40
39
}
41
40
const cacheDir = await getOrCreateCacheDir ( ) ;
42
- const filename = getLocalFilename ( url ) ;
41
+ const filename = await getLocalFilename ( url ) ;
43
42
const filepath = path . join ( cacheDir , filename ) ;
44
43
if ( await fs . exists ( filepath ) ) {
45
44
return filepath ;
@@ -58,11 +57,16 @@ async function ensureLocalFile(url: URL): Promise<string> {
58
57
return filepath ;
59
58
}
60
59
61
- function getLocalFilename ( url : URL ) : string {
62
- const h = hash . createHash ( "sha256" ) ;
63
- h . update ( url . href ) ;
60
+ async function getLocalFilename ( url : URL ) : Promise < string > {
61
+ const buf = await crypto . subtle . digest (
62
+ "sha-256" ,
63
+ new TextEncoder ( ) . encode ( url . href ) ,
64
+ ) ;
65
+ const h = Array . from ( new Uint8Array ( buf ) )
66
+ . map ( ( b ) => b . toString ( 16 ) . padStart ( 2 , "0" ) )
67
+ . join ( "" ) ;
64
68
const basename = path . basename ( url . pathname ) ;
65
- return `${ h . toString ( ) } -${ basename } ` ;
69
+ return `${ h } -${ basename } ` ;
66
70
}
67
71
68
72
async function getOrCreateCacheDir ( ) : Promise < string > {
0 commit comments