@@ -46,24 +46,6 @@ const readPipeline = (cpath, size, sri, stream) => {
4646 return stream
4747}
4848
49- module . exports . sync = readSync
50-
51- function readSync ( cache , integrity , opts = { } ) {
52- const { size } = opts
53- return withContentSriSync ( cache , integrity , ( cpath , sri ) => {
54- const data = fs . readFileSync ( cpath , { encoding : null } )
55- if ( typeof size === 'number' && size !== data . length ) {
56- throw sizeError ( size , data . length )
57- }
58-
59- if ( ssri . checkData ( data , sri ) ) {
60- return data
61- }
62-
63- throw integrityError ( sri , cpath )
64- } )
65- }
66-
6749module . exports . stream = readStream
6850module . exports . readStream = readStream
6951
@@ -88,20 +70,13 @@ function readStream (cache, integrity, opts = {}) {
8870}
8971
9072module . exports . copy = copy
91- module . exports . copy . sync = copySync
9273
9374function copy ( cache , integrity , dest ) {
9475 return withContentSri ( cache , integrity , ( cpath , sri ) => {
9576 return fs . copyFile ( cpath , dest )
9677 } )
9778}
9879
99- function copySync ( cache , integrity , dest ) {
100- return withContentSriSync ( cache , integrity , ( cpath , sri ) => {
101- return fs . copyFileSync ( cpath , dest )
102- } )
103- }
104-
10580module . exports . hasContent = hasContent
10681
10782async function hasContent ( cache , integrity ) {
@@ -130,34 +105,6 @@ async function hasContent (cache, integrity) {
130105 }
131106}
132107
133- module . exports . hasContent . sync = hasContentSync
134-
135- function hasContentSync ( cache , integrity ) {
136- if ( ! integrity ) {
137- return false
138- }
139-
140- return withContentSriSync ( cache , integrity , ( cpath , sri ) => {
141- try {
142- const stat = fs . statSync ( cpath )
143- return { size : stat . size , sri, stat }
144- } catch ( err ) {
145- if ( err . code === 'ENOENT' ) {
146- return false
147- }
148-
149- if ( err . code === 'EPERM' ) {
150- /* istanbul ignore else */
151- if ( process . platform !== 'win32' ) {
152- throw err
153- } else {
154- return false
155- }
156- }
157- }
158- } )
159- }
160-
161108async function withContentSri ( cache , integrity , fn ) {
162109 const sri = ssri . parse ( integrity )
163110 // If `integrity` has multiple entries, pick the first digest
@@ -201,28 +148,6 @@ async function withContentSri (cache, integrity, fn) {
201148 }
202149}
203150
204- function withContentSriSync ( cache , integrity , fn ) {
205- const sri = ssri . parse ( integrity )
206- // If `integrity` has multiple entries, pick the first digest
207- // with available local data.
208- const algo = sri . pickAlgorithm ( )
209- const digests = sri [ algo ]
210- if ( digests . length <= 1 ) {
211- const cpath = contentPath ( cache , digests [ 0 ] )
212- return fn ( cpath , digests [ 0 ] )
213- } else {
214- let lastErr = null
215- for ( const meta of digests ) {
216- try {
217- return withContentSriSync ( cache , meta , fn )
218- } catch ( err ) {
219- lastErr = err
220- }
221- }
222- throw lastErr
223- }
224- }
225-
226151function sizeError ( expected , found ) {
227152 /* eslint-disable-next-line max-len */
228153 const err = new Error ( `Bad data size: expected inserted data to be ${ expected } bytes, but got ${ found } instead` )
0 commit comments