Merge pull request #17714 from Snuffleupagus/Node-fs-promise
Use `fs/promises` in the Node.js-specific code in the `src/`-folder
This commit is contained in:
		
						commit
						e650b95253
					
				| @ -424,21 +424,22 @@ class PDFNodeStreamFsFullReader extends BaseFullReader { | |||||||
|       path = path.replace(/^\//, ""); |       path = path.replace(/^\//, ""); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fs.lstat(path, (error, stat) => { |     fs.promises.lstat(path).then( | ||||||
|       if (error) { |       stat => { | ||||||
|         if (error.code === "ENOENT") { |  | ||||||
|           error = new MissingPDFException(`Missing PDF "${path}".`); |  | ||||||
|         } |  | ||||||
|         this._storedError = error; |  | ||||||
|         this._headersCapability.reject(error); |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|         // Setting right content length.
 |         // Setting right content length.
 | ||||||
|         this._contentLength = stat.size; |         this._contentLength = stat.size; | ||||||
| 
 | 
 | ||||||
|         this._setReadableStream(fs.createReadStream(path)); |         this._setReadableStream(fs.createReadStream(path)); | ||||||
|         this._headersCapability.resolve(); |         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) { | const fetchData = function (url) { | ||||||
|   return new Promise((resolve, reject) => { |   return fs.promises.readFile(url).then(data => new Uint8Array(data)); | ||||||
|     fs.readFile(url, (error, data) => { |  | ||||||
|       if (error || !data) { |  | ||||||
|         reject(new Error(error)); |  | ||||||
|         return; |  | ||||||
|       } |  | ||||||
|       resolve(new Uint8Array(data)); |  | ||||||
|     }); |  | ||||||
|   }); |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| class NodeFilterFactory extends BaseFilterFactory {} | class NodeFilterFactory extends BaseFilterFactory {} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user