# ¾îÇø®ÄÉÀÌ¼Ç ÆÐŰ¡ ¾îÇø®ÄÉÀ̼ÇÀÇ ¸®¼Ò½º¿Í ¼Ò½ºÄڵ带 À¯Àú·ÎºÎÅÍ º¸È£Çϱâ À§ÇØ, ¾à°£ÀÇ ±¸Á¶ º¯°æÀ¸·Î ¾îÇø®ÄÉÀ̼ÇÀ» [asar][asar] ¾ÆÄ«À̺ê·Î ÆÐŰ¡ ÇÒ ¼ö ÀÖ½À´Ï´Ù. ## `asar` ¾ÆÄ«ÀÌºê »ý¼º [asar][asar]¾ÆÄ«À̺ê´Â tar°ú ºñ½ÁÇÑ Æ÷¸ËÀ¸·Î ¸ðµç ¸®¼Ò½º¸¦ ÇϳªÀÇ ÆÄÀÏ·Î ¸¸µì´Ï´Ù. ±×¸®°í ElectronÀº ¾ÐÃàÇØÁ¦ ¾øÀÌ ÀÓÀÇ·Î ¸ðµç ÆÄÀÏÀ» ÀоîµéÀÏ ¼ö ÀÖ½À´Ï´Ù. ´ÙÀ½ ¸î°¡Áö ´Ü°è¸¦ ÅëÇØ ¾îÇø®ÄÉÀ̼ÇÀ» `asar` ¾ÆÄ«À̺ê·Î ¾ÐÃàÇÒ ¼ö ÀÖ½À´Ï´Ù: ### 1. asar À¯Æ¿¸®Æ¼ ¼³Ä¡ ```bash $ npm install -g asar ``` ### 2. `asar pack` Ä¿¸Çµå·Î ¾Û ÆÐŰ¡ ```bash $ asar pack your-app app.asar ``` ## `asar` ¾ÆÄ«ÀÌºê »ç¿ëÇϱâ ElectronÀº µÎ°¡ÁöÀÇ API¸¦ °¡Áö°í ÀÖ½À´Ï´Ù: Node.js·Î ºÎÅÍ Á¦°øµÈ Node API, ChromiumÀ¸·ÎºÎÅÍ Á¦°øµÈ Web API. µÎ API ¸ðµÎ `asar`¿¡¼­ ÀоîµéÀÏ ¼ö ÀÖµµ·Ï Áö¿øÇÕ´Ï´Ù. ### Node API `fs.readFile` ¿Í `require` °°Àº Node APIµéÀ» Áö¿øÇϱâ À§ÇØ Electron¿¡¼± `asar` ¾ÆÄ«À̺갡 °¡»óÀÇ µð·ºÅ͸® ±¸Á¶¸¦ °¡Áöµµ·Ï ÆÐÄ¡Çß½À´Ï´Ù. ±×·¡¼­ ¾ÆÄ«ÀÌºê ³»ºÎ¿¡¼­ ¸®¼Ò½ºµéÀ» Á¤»óÀûÀÎ ÆÄÀÏ ½Ã½ºÅÛó·³ Á¢±ÙÇÒ ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦µé¾î, `/path/to`¶ó´Â °æ·Î¿¡ `example.asar`¶ó´Â ¾ÆÄ«À̺갡 ÀÖ´Ù°í °¡Á¤Çϸé: ```bash $ asar list /path/to/example.asar /app.js /file.txt /dir/module.js /static/index.html /static/main.css /static/jquery.min.js ``` `asar` ¾ÆÄ«À̺꿡¼± ´ÙÀ½°ú °°ÀÌ ÆÄÀÏÀ» ÀÐÀ» ¼ö ÀÖ½À´Ï´Ù: ```javascript var fs = require('fs'); fs.readFileSync('/path/to/example.asar/file.txt'); ``` ¾ÆÄ«ÀÌºê ³»ÀÇ ·çÆ® µð·ºÅ͸®¸¦ ¸®½ºÆÃÇÕ´Ï´Ù: ```javascript var fs = require('fs'); fs.readdirSync('/path/to/example.asar'); ``` ¾ÆÄ«ÀÌºê ¾ÈÀÇ ¸ðµâ »ç¿ëÇϱâ: ```javascript require('/path/to/example.asar/dir/module.js'); ``` `BrowserWindow` Ŭ·¡½º¸¦ ÀÌ¿ëÇØ ¿øÇÏ´Â À¥ ÆäÀÌÁöµµ Ç¥½ÃÇÒ ¼ö ÀÖ½À´Ï´Ù: ```javascript var BrowserWindow = require('browser-window'); var win = new BrowserWindow({width: 800, height: 600}); win.loadUrl('file:///path/to/example.asar/static/index.html'); ``` ### Web API À¥ ÆäÀÌÁö ³»¿¡¼±, ¾ÆÄ«ÀÌºê ³»ÀÇ ÆÄÀÏÀ» `file:` ÇÁ·ÎÅäÄÝÀ» »ç¿ëÇÏ¿© ¿äûÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ ¶ÇÇÑ Node API¿Í °°ÀÌ °¡»ó µð·ºÅ͸® ±¸Á¶¸¦ °¡Áý´Ï´Ù. ¿¹¸¦µé¾î, jQueryÀÇ `$.get`À» »ç¿ëÇÏ¿© ÆÄÀÏÀ» °¡Á®¿Ã ¼ö ÀÖ½À´Ï´Ù: ```html ``` ### `asar` ¾ÆÄ«À̺긦 ÀÏ¹Ý ÆÄÀÏ·Î Ãë±ÞÇϱâ `asar` ¾ÆÄ«À̺êÀÇ Ã¼Å©¼¶(checksum)µîÀ» °Ë»çÇϱâ À§Çؼ±, `asar` ¾ÆÄ«À̺긦 ÆÄÀÏ ±×´ë·Î Àоîµé¿©¾ß ÇÒ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù. ÀÌ ÀÛ¾÷À» Çϱâ À§ÇØ `original-fs`¶ó°í ÇÏ´Â ºôÆ®ÀÎ ¸ðµâÀ» `fs` ¸ðµâ ´ë½Å¿¡ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ ¸ðµâÀº `asar` Áö¿øÀÌ ºüÁ®ÀÖ½À´Ï´Ù. Áï ÆÄÀÏ ±×´ë·Î¸¦ ÀоîµéÀÔ´Ï´Ù: ```javascript var originalFs = require('original-fs'); originalFs.readFileSync('/path/to/example.asar'); ``` ## Node APIÀÇ ÇÑ°è `asar` ¾ÆÄ«À̺긦 Node API°¡ ÃÖ´ëÇÑ µð·ºÅ͸® ±¸Á¶·Î ÀÛµ¿Çϵµ·Ï ³ë·ÂÇØ¿ÔÁö¸¸, ¿©ÀüÈ÷ Àú¼öÁØ(low-level) Node API ¶§¹®¿¡ ÇÑ°è°¡ ÀÖ½À´Ï´Ù. Even though we tried hard to make `asar` archives in the Node API work like directories as much as possible, there are still limitations due to the low-level nature of the Node API. ### ¾ÆÄ«À̺ê´Â Àбâ Àü¿ëÀÔ´Ï´Ù ¾ÆÄ«À̺ê´Â ¼öÁ¤ÇÒ ¼ö ¾øÀ¸¸ç ±âº»ÀûÀ¸·Î´Â Node API·Î ÆÄÀÏÀ» ¼öÁ¤ÇÒ ¼ö ÀÖÁö¸¸, `asar` ¾ÆÄ«À̺꿡¼± ÀÛµ¿ÇÏÁö ¾Ê½À´Ï´Ù. ### ¾ÆÄ«ÀÌºê ¾ÈÀÇ µð·ºÅ͸®¸¦ ÀÛ¾÷ °æ·Î·Î ¼³Á¤ÇÏ¸é ¾ÈµË´Ï´Ù `asar` ¾ÆÄ«À̺ê´Â µð·ºÅ͸®Ã³·³ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ±¸ÇöµÇ¾úÁö¸¸, ±×°ÍÀº ½ÇÁ¦ ÆÄÀϽýºÅÛÀÇ µð·ºÅ͸®°¡ ¾Æ´Ñ °¡»óÀÇ µð·ºÅ͸®ÀÔ´Ï´Ù. ±×·± ÀÌÀ¯·Î ¸î¸î API¿¡¼­ Áö¿øÇÏ´Â `cwd` ¿É¼ÇÀ» `asar` ¾ÆÄ«ÀÌºê ¾ÈÀÇ µð·ºÅ͸® °æ·Î·Î ÁöÁ¤ÇÏ¸é ³ªÁß¿¡ ¹®Á¦°¡ ¹ß»ýÇÒ ¼ö ÀÖ½À´Ï´Ù. ### ƯÁ¤ API·Î ÀÎÇÑ ¿¹¿ÜÀûÀÎ ¾ÐÃà ÇØÁ¦ ¸¹Àº `fs` API°¡ `asar` ¾ÆÄ«À̺êÀÇ ¾ÐÃàÀ» ÇØÁ¦ÇÏÁö ¾Ê°í ¹Ù·Î ¾ÆÄ«À̺긦 Àаųª Á¤º¸¸¦ °¡Á®¿Ã ¼ö ÀÖÀ¸³ª, ¸î¸î API´Â ½Ã½ºÅÛÀÇ ½ÇÁ¦ ÆÄÀÏÀÇ °æ·Î¸¦ ±â¹ÝÀ¸·Î ÀÛµ¿ÇϹǷΠÀÌ APIµéÀ» »ç¿ëÇÒ ¶© ElectronÀº ÀÌ API°¡ ¿øÇÒÇÏ°Ô ÀÛµ¿ÇÒ ¼ö ÀÖµµ·Ï Çϱâ À§ÇØ Àӽðæ·Î¿¡ ÇØ´ç ÆÄÀϵéÀÇ ¾ÐÃàÀ» ÇØÁ¦ÇÕ´Ï´Ù. ÀÌ ÀÛ¾÷Àº ¾à°£ÀÇ ¿À¹öÇìµå¸¦ ºÒ·¯ ÀÏÀ¸Å³ ¼ö ÀÖ½À´Ï´Ù. ÇØ´çÇÏ´Â API ÇÔ¼ö´Â ´ÙÀ½°ú °°½À´Ï´Ù: * `child_process.execFile` * `fs.open` * `fs.openSync` * `process.dlopen` - Used by `require` on native modules ### `fs.stat`ÀÇ À߸øµÈ ½ºÅ×ÀÌÅͽº `fs.stat` ·Î ºÎÅÍ ¹ÝȯµÇ´Â `Stats` °´Ã¼¿Í ºñ½ÁÇÑ APIµéÀº `asar` ¾ÆÄ«À̺긦 Ÿ°ÙÀ¸·Î ÇÒ °æ¿ì °¡»óÀÇ ¿¹ÃøµÈ Á¤º¸¸¦ °¡Áý´Ï´Ù. ¿Ö³ÄÇÏ¸é ¾ÆÄ«À̺êÀÇ µð·ºÅ͸® °æ·Î´Â ½ÇÁ¦ ÆÄÀϽýºÅÛ¿¡ Á¸ÀçÇÏÁö ¾Ê±â ¶§¹®ÀÔ´Ï´Ù. ±×·¯ÇÑ ÀÌÀ¯·Î ÆÄÀÏ Å©±â¿Í ÆÄÀÏ Å¸ÀÔ µîÀ» È®ÀÎÇÒ ¶§ `Stats` °´Ã¼¸¦ ½Å·ÚÇؼ± ¾ÈµË´Ï´Ù. ## Adding unpacked files in `asar` archive Àü¼úÇÑ ¹Ù¿Í °°ÀÌ, ¸î¸î Node API´Â È£Ã⠽à ÇØ´ç ÆÄÀÏÀ» ÀÓ½ÃÆú´õ¿¡ ¾ÐÃàÀ» ÇØÁ¦ÇÕ´Ï´Ù. µû·Î ¼º´É¹®Á¦°¡ ¹ß»ýÇÒ ¼ö ÀÖ½À´Ï´Ù. ±×¸®°í ¹é½Å ¼ÒÇÁÆ®¿þ¾îÀÇ À߸øµÈ ¿ÀÁøÀ» ÀÏÀ¸Å³ ¼öµµ ÀÖ½À´Ï´Ù. ÀÌ ¹®Á¦¸¦ ÇØ°áÇÏ·Á¸é, `--unpack` ¿É¼ÇÀ» È°¿ëÇÏ¿© ÆÄÀÏÀ» ¾ÐÃàÀÌ Ç®·ÁÁø »óÅ·ΠÀ¯ÁöÇØ¾ß ÇÕ´Ï´Ù. ´ÙÀ½ÀÇ ¿¹Á¦´Â node ³×ÀÌƼºê ¸ðµâÀÇ °øÀ¯ ¶óÀ̺귯¸®¸¦ unpack »óÅ·ΠÀ¯ÁöÇÕ´Ï´Ù: ```bash $ asar pack app app.asar --unpack *.node ``` Ä¿¸Çµå¸¦ ½ÇÇàÇÑ ÈÄ, °°Àº µð·ºÅ͸®¿¡ `app.asar` ÆÄÀÏ ¿Ü¿¡ `app.asar.unpacked` Æú´õ°¡ °°ÀÌ »ý¼ºµË´Ï´Ù. ÀÌ Æú´õ¾È¿¡ unpack ¿É¼Ç¿¡¼­ ¼³Á¤ÇÑ ÆÄÀϵéÀÌ ¾ÐÃàÀÌ Ç®¸° »óÅ·ΠÆ÷ÇԵǾî ÀÖ½À´Ï´Ù. À¯Àú¿¡°Ô ¾îÇø®ÄÉÀ̼ÇÀ» ¹èÆ÷ÇÒ ¶§ ¹Ýµå½Ã ÇØ´ç Æú´õµµ °°ÀÌ ¹èÆ÷ÇÏ¿©¾ßÇÕ´Ï´Ù. [asar]: https://github.com/atom/asar