]> khamidou — GitHub mirrors - electron.git/commitdiff
Make process.dlopen work for asar packages.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 13:49:28 +0000 (21:49 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 25 Sep 2014 13:49:28 +0000 (21:49 +0800)
atom/common/lib/asar.coffee

index f3f9fc6a85507ca786dc05912340bdafe0672dc4..98e30535342deed0ee35fda45da21ca55b9d844c 100644 (file)
@@ -220,3 +220,16 @@ fs.readdirSync = (p) ->
   throw createNotFoundError(asarPath, filePath) unless files
 
   files
+
+dlopen = process.dlopen
+require('module')._extensions['.node'] = process.dlopen = (module, p) ->
+  [isAsar, asarPath, filePath] = splitPath p
+  return dlopen.apply this, arguments unless isAsar
+
+  archive = getOrCreateArchive asarPath
+  throw new Error("Invalid package #{asarPath}") unless archive
+
+  newPath = archive.copyFileOut filePath
+  throw createNotFoundError(asarPath, filePath) unless newPath
+
+  dlopen module, newPath