cocos2d / cocos2d-html5

Cocos2d for Web Browsers. Built using JavaScript.
https://www.cocos.com
3.06k stars 903 forks source link

Decompress password protected zip [feature] #2116

Open hsdk123 opened 10 years ago

hsdk123 commented 10 years ago

I noticed the compression related files in cocos2d-html5 - I feel it would be great if decompression of password protected zip files would be added as a feature.

This would be a big help for ex. node-webkit cocos2d-html5 applications that need graphics, music resources protected from normal players.

layerssss commented 10 years ago

I think a better approach would be: adding a hook for deciphering file data immediately after having retrieved bytes from xhr.

because:

layerssss commented 10 years ago

Hi, here's the plan:

  1. let cc.loader.loadImg() work through xhr(arraybuffer) => blob => blob url => HTMLImage (instead of directly using HTMLImage, this could also bring possibilities for tracking load progress for eg. cc.LoaderScene.preload())
  2. let cc.loader.loadTxt() load arraybuffer, then convert the result to string. ( http://stackoverflow.com/questions/6965107/converting-between-strings-and-arraybuffers )
  3. loadFont/loadAudio are similar to 1. , xhr(arraybuffer) => blob => blob url => ... releventHTMLTags
  4. let cc.loader.handlingResourceBuffer default to function(bufferArray){ return bufferArray; }. It can be overridden by users.
  5. Add explicit example code in template/src/resource.js. (for overriding cc.loader.handlingResourceBuffer)

if it's ok, I'll try to make a patch. @dingpinglv

hsdk123 commented 10 years ago

@layerssss Thanks for the replies, that would seem to do the trick. I'll let you know if it works after the patch.