11'use strict'
22
3- var fs = require ( "fs" ) ;
4- var os = require ( "os" ) ;
5- const { encode : encodeQuery } = require ( 'querystring' )
6- const { strictEqual} = require ( 'assert' )
7- const envPaths = require ( 'env-paths' )
8- const FileCache = require ( '@derhuerst/http-basic/lib/FileCache' ) . default
9- const { extname} = require ( 'path' )
10- var ProgressBar = require ( "progress" ) ;
11- var request = require ( '@derhuerst/http-basic' )
12- const { createGunzip} = require ( 'zlib' )
13- const { pipeline} = require ( 'stream' )
14- var ffmpegPath = require ( "." ) ;
15- var pkg = require ( "./package" ) ;
3+ import { statSync , createWriteStream , chmodSync } from 'node:fs'
4+ import { arch as osArch , platform as osPlatform } from 'node:os'
5+ import HttpsProxyAgent from 'https-proxy-agent'
6+ import { encode as encodeQuery } from 'node:querystring'
7+ import { strictEqual } from 'node:assert'
8+ import envPaths from 'env-paths'
9+ import httpBasic from '@derhuerst/http-basic'
10+ const { FileCache} = httpBasic
11+ import { extname } from 'node:path'
12+ import ProgressBar from 'progress'
13+ import request from '@derhuerst/http-basic'
14+ import { createGunzip } from 'node:zlib'
15+ import { pipeline } from 'node:stream'
16+ import ffmpegPath from './index.js'
17+
18+ import { createRequire } from 'node:module'
19+ const require = createRequire ( import . meta. url )
20+ const pkg = require ( './package.json' )
1621
1722const exitOnError = ( err ) => {
1823 console . error ( err )
@@ -28,7 +33,7 @@ if (!ffmpegPath) {
2833}
2934
3035try {
31- if ( fs . statSync ( ffmpegPath ) . isFile ( ) ) {
36+ if ( statSync ( ffmpegPath ) . isFile ( ) ) {
3237 console . info ( 'ffmpeg is installed already.' )
3338 process . exit ( 0 )
3439 }
@@ -45,7 +50,6 @@ const proxyUrl = (
4550 process . env . http_proxy
4651)
4752if ( proxyUrl ) {
48- const HttpsProxyAgent = require ( 'https-proxy-agent' )
4953 const { hostname, port, protocol} = new URL ( proxyUrl )
5054 agent = new HttpsProxyAgent ( { hostname, port, protocol} )
5155}
@@ -109,7 +113,7 @@ function downloadFile(url, destinationPath, progressCallback = noop) {
109113 return ;
110114 }
111115
112- const file = fs . createWriteStream ( destinationPath ) ;
116+ const file = createWriteStream ( destinationPath ) ;
113117 const streams = isGzUrl ( url )
114118 ? [ response . body , createGunzip ( ) , file ]
115119 : [ response . body , file ]
@@ -159,8 +163,8 @@ const releaseName = (
159163 pkg [ 'ffmpeg-static' ] [ 'binary-release-name' ] ||
160164 release
161165)
162- const arch = process . env . npm_config_arch || os . arch ( )
163- const platform = process . env . npm_config_platform || os . platform ( )
166+ const arch = process . env . npm_config_arch || osArch ( )
167+ const platform = process . env . npm_config_platform || osPlatform ( )
164168
165169const baseUrl = `https://github.com/eugeneware/ffmpeg-static/releases/download/${ release } `
166170const downloadUrl = `${ baseUrl } /${ platform } -${ arch } .gz`
@@ -169,7 +173,7 @@ const licenseUrl = `${baseUrl}/${platform}-${arch}.LICENSE`
169173
170174downloadFile ( downloadUrl , ffmpegPath , onProgress )
171175. then ( ( ) => {
172- fs . chmodSync ( ffmpegPath , 0o755 ) // make executable
176+ chmodSync ( ffmpegPath , 0o755 ) // make executable
173177} )
174178. catch ( exitOnError )
175179
0 commit comments