11const requestFileAccess = require ( p . join ( appDir , 'scripts/file-manager/request-file-access.js' ) )
2- filePassword = require ( p . join ( appDir , 'scripts/file-manager/file-password.js' ) ) ;
2+ filePassword = require ( p . join ( appDir , 'scripts/file-manager/file-password.js' ) ) ,
3+ diskType = require ( p . join ( appDir , 'scripts/file-manager/disk-type.js' ) ) ;
34
45var un7z = false , bin7z = false , fastXmlParser = false , Minimatch = false ;
56
@@ -1869,6 +1870,17 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
18691870
18701871 }
18711872
1873+ this . getOptimalThreads = function ( ) {
1874+
1875+ const disk = diskType . check ( this . realPath ) ;
1876+
1877+ if ( disk . hdd )
1878+ return { readKey : 'readUsingThreadsHDD' , extractKey : 'extractUsingThreadsHDD' , read : 0.01 , extract : 0.01 } ;
1879+ else
1880+ return { readKey : 'readUsingThreads' , extractKey : 'extractUsingThreads' , read : 1 , extract : 1 } ;
1881+
1882+ }
1883+
18721884 // 7z
18731885 this . _7z = false ;
18741886
@@ -1893,51 +1905,67 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
18931905
18941906 this . read7z = async function ( callback = false ) {
18951907
1896- const files = [ ] ;
1897-
18981908 const self = this ;
1909+ const optimalThreads = this . getOptimalThreads ( ) ;
18991910
1900- const _7z = await this . open7z ( ) ;
1901- let readSome = false ;
1911+ return threads . job ( optimalThreads . readKey , { useThreads : optimalThreads . read } , async function ( ) {
19021912
1903- return new Promise ( function ( resolve , reject ) {
1913+ return new Promise ( async function ( resolve , reject ) {
19041914
1905- _7z . on ( 'data' , function ( data ) {
1915+ let readSome = false ;
1916+ let endEvent = false ;
19061917
1907- if ( data . file )
1908- {
1909- if ( / ^ D / . test ( data . attributes ) && ! data . size ) // Ignore directories
1910- return ;
1918+ const files = [ ] ;
1919+ const _7z = await self . open7z ( ) ;
19111920
1912- const originalName = self . removeTmp ( p . normalize ( data . file ) ) ;
1913- const name = self . fixUnsupportedCharsInWindows ( originalName ) ;
1914- const same = originalName === name ? true : false ;
1921+ _7z . on ( 'data' , function ( data ) {
19151922
1916- files . push ( { name : name , fixedName : ( ! same ? name : '' ) , originalName : ( ! same ? originalName : '' ) , path : p . join ( self . path , name ) , fileSize : data . size } ) ;
1917- self . setFileStatus ( name , { extracted : false } ) ;
1923+ if ( data . file )
1924+ {
1925+ if ( / ^ D / . test ( data . attributes ) && ! data . size ) // Ignore directories
1926+ return ;
19181927
1919- readSome = true ;
1920- }
1928+ const originalName = self . removeTmp ( p . normalize ( data . file ) ) ;
1929+ const name = self . fixUnsupportedCharsInWindows ( originalName ) ;
1930+ const same = originalName === name ? true : false ;
19211931
1922- } ) . on ( 'end' , function ( data ) {
1932+ files . push ( { name : name , fixedName : ( ! same ? name : '' ) , originalName : ( ! same ? originalName : '' ) , path : p . join ( self . path , name ) , fileSize : data . size } ) ;
1933+ self . setFileStatus ( name , { extracted : false } ) ;
19231934
1924- self . files = self . filesToMultidimension ( files ) ;
1925- resolve ( self . files ) ;
1935+ readSome = true ;
1936+ }
19261937
1927- } ) . on ( 'error ' , function ( error ) {
1938+ } ) . on ( 'end ' , function ( data ) {
19281939
1929- if ( readSome )
1930- {
1931- /*self.files = self.filesToMultidimension(files);
1932- resolve(self.files);*/
1940+ endEvent = true ;
19331941
1934- //self.saveErrorToCache(error);
1935- dom . compressedError ( error , false , sha1 ( self . path ) ) ;
1936- }
1937- else
1938- {
1939- reject ( error ) ;
1940- }
1942+ self . files = self . filesToMultidimension ( files ) ;
1943+ resolve ( self . files ) ;
1944+
1945+ } ) . on ( 'error' , function ( error ) {
1946+
1947+ if ( readSome )
1948+ {
1949+ //self.saveErrorToCache(error);
1950+ dom . compressedError ( error , false , sha1 ( self . path ) ) ;
1951+
1952+ // Just in case the 'end' event is not called
1953+ setTimeout ( function ( ) {
1954+
1955+ if ( endEvent )
1956+ return ;
1957+
1958+ self . files = self . filesToMultidimension ( files ) ;
1959+ resolve ( self . files ) ;
1960+
1961+ } , 5000 ) ;
1962+ }
1963+ else
1964+ {
1965+ reject ( error ) ;
1966+ }
1967+
1968+ } ) ;
19411969
19421970 } ) ;
19431971
@@ -1948,6 +1976,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
19481976 this . extract7z = async function ( ) {
19491977
19501978 const self = this ;
1979+ const optimalThreads = this . getOptimalThreads ( ) ;
19511980
19521981 const only = [ ] ;
19531982 const extractName = { } ;
@@ -1979,7 +2008,7 @@ var fileCompressed = function(path, _realPath = false, forceType = false, prefix
19792008 let extractedSome = false ;
19802009 let hasError = false ;
19812010
1982- promises . push ( threads . job ( 'extractUsingThreads' , { useThreads : 1 } , async function ( ) {
2011+ promises . push ( threads . job ( optimalThreads . extractKey , { useThreads : optimalThreads . extract } , async function ( ) {
19832012
19842013 return new Promise ( async function ( resolve , reject ) {
19852014
@@ -3600,4 +3629,5 @@ module.exports = {
36003629 fileSizes : function ( ) { return fileSizes } ,
36013630 requestFileAccess : requestFileAccess ,
36023631 filePassword : filePassword ,
3632+ diskType : diskType ,
36033633}
0 commit comments