Use fs/promises in the Node.js-specific code in the src/-folder
				
					
				
			This is available in all Node.js versions that we currently support, and using it allows us to remove callback-functions; please see https://nodejs.org/docs/latest-v18.x/api/fs.html#promises-api
This commit is contained in:
		
							parent
							
								
									72b8b29147
								
							
						
					
					
						commit
						db2849cc17
					
				| @ -424,21 +424,22 @@ class PDFNodeStreamFsFullReader extends BaseFullReader { | ||||
|       path = path.replace(/^\//, ""); | ||||
|     } | ||||
| 
 | ||||
|     fs.lstat(path, (error, stat) => { | ||||
|       if (error) { | ||||
|         if (error.code === "ENOENT") { | ||||
|           error = new MissingPDFException(`Missing PDF "${path}".`); | ||||
|         } | ||||
|         this._storedError = error; | ||||
|         this._headersCapability.reject(error); | ||||
|         return; | ||||
|       } | ||||
|     fs.promises.lstat(path).then( | ||||
|       stat => { | ||||
|         // Setting right content length.
 | ||||
|         this._contentLength = stat.size; | ||||
| 
 | ||||
|         this._setReadableStream(fs.createReadStream(path)); | ||||
|         this._headersCapability.resolve(); | ||||
|     }); | ||||
|       }, | ||||
|       error => { | ||||
|         if (error.code === "ENOENT") { | ||||
|           error = new MissingPDFException(`Missing PDF "${path}".`); | ||||
|         } | ||||
|         this._storedError = error; | ||||
|         this._headersCapability.reject(error); | ||||
|       } | ||||
|     ); | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -71,15 +71,7 @@ if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("SKIP_BABEL")) { | ||||
| } | ||||
| 
 | ||||
| const fetchData = function (url) { | ||||
|   return new Promise((resolve, reject) => { | ||||
|     fs.readFile(url, (error, data) => { | ||||
|       if (error || !data) { | ||||
|         reject(new Error(error)); | ||||
|         return; | ||||
|       } | ||||
|       resolve(new Uint8Array(data)); | ||||
|     }); | ||||
|   }); | ||||
|   return fs.promises.readFile(url).then(data => new Uint8Array(data)); | ||||
| }; | ||||
| 
 | ||||
| class NodeFilterFactory extends BaseFilterFactory {} | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user