pubo-node 1.0.46 → 1.0.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pubo-node.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-node"]=e():t["pubo-node"]=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=6)}([function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("pubo-utils")},function(t,e){t.exports=require("pako")},function(t,e){t.exports=require("path")},function(t,e){t.exports=require("child_process")},function(t,e){t.exports=require("crypto")},function(t,e,n){"use strict";n.r(e),n.d(e,"JsonStorage",(function(){return s})),n.d(e,"initRtspVideos",(function(){return O})),n.d(e,"RtspVideosManager",(function(){return g})),n.d(e,"FtpClient",(function(){return E})),n.d(e,"md5",(function(){return k})),n.d(e,"createRpcClient",(function(){return F}));var r=n(0),o=n(2),i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},s=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=Object(r.readFileSync)(this.path),e=o.inflate(t,{to:"string"});this._state=JSON.parse(e)}catch(t){this.state={}}},Object.defineProperty(t.prototype,"state",{get:function(){return this._state},set:function(t){var e=o.deflate(JSON.stringify(t)),n=Buffer.from(e);Object(r.writeFile)(this.path,n,(function(t){return t&&console.log(t)})),this._state=t},enumerable:!1,configurable:!0}),t.prototype.get=function(t){return t?this.state[t]:i({},this.state)},t.prototype.set=function(t,e){var n=i({},this.state);n[t]=e,this.state=n},t.prototype.merge=function(t){this.state=i(i({},this._state),t)},t}(),u=n(3),c=n(4),a=n(1),l=function(){return(l=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},f=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},p=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(f(arguments[e]));return t},h=function(){function t(t,e){var n=this;this.eventEmitter=new a.Emitter,this.dog=new a.WatchDog({limit:10,onTimeout:function(){return n.connect()}}),this.url=t,this.options=l({},e),this.options.input||(this.options.input=["-rtsp_transport","tcp","-i"]),this.options.output||(this.options.output=["-f","mpegts","-codec:v","mpeg1video"]),this.connect(),this.dog.init()}return t.prototype.onMessage=function(t){this.dog.feed(),this.eventEmitter.emit("message",t.toString())},t.prototype.closeOld=function(){this.s&&(console.log("LOG Video-Server: "+this.url+" try to reconnect;"),this.s.kill(),this.s=null)},t.prototype.connect=function(){var t=this;this.closeOld();var e=p(this.options.input,[this.url],this.options.output,["-"]);this.s=Object(c.spawn)("ffmpeg",e,{detached:!1}),this.s.stderr.on("data",(function(e){return t.onMessage(e)})),this.s.stdout.on("data",(function(e){return t.eventEmitter.emit("data",e)}))},t.prototype.on=function(t,e){return this.eventEmitter.on(t,e)},t.prototype.cancel=function(t){this.eventEmitter.cancel(t)},t.prototype.destroy=function(){this.eventEmitter.clear(),this.dog.stop(),this.s&&(this.s.kill(),this.s=null)},t}(),y=function(){return(y=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},d=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},m=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v(arguments[e]));return t},b=function(){function t(){this.path=Object(u.resolve)("resources/temp/videos.json")}return t.prototype.async=function(t){try{Object(r.writeFileSync)(this.path,JSON.stringify(t))}catch(t){console.log(t)}},Object.defineProperty(t.prototype,"data",{get:function(){try{var t=Object(r.readFileSync)(this.path);return console.log(t.toString()),JSON.parse(t.toString())}catch(t){return console.log(t),null}},enumerable:!1,configurable:!0}),t}(),g=function(){function t(t){this._system=[],this._customer=[],this.system=[],this.customer=[],this.storage=new b,this._system=t.map((function(t){return y(y({},t),{system:!0})})),this._customer=this.storage.data||[],this.system=t.map((function(t){var e=t.url,n=d(t,["url"]);return new h(e,n)})),this.customer=this._customer.map((function(t){var e=t.url,n=d(t,["url"]);return new h(e,n)}))}return Object.defineProperty(t.prototype,"list",{get:function(){return m(this.system,this.customer)},enumerable:!1,configurable:!0}),t.prototype.getVideos=function(){return m(this._system,this._customer)},t.prototype.create=function(t){if(this._customer.some((function(e){return e.url===t.url})))throw new Error("该地址已存在");var e=new h(t.url,t);this._customer.push(t),this.customer.push(e),this.storage.async(this._customer)},t.prototype.remove=function(t){if(t<this.system.length)throw new Error("系统配置不可删除");if(t>this.system.length+this.customer.length-1)throw new Error("超限");this._customer.splice(t-this.system.length-1,1),this.customer.splice(t-this.system.length-1,1)[0].destroy(),this.storage.async(this._customer)},t}(),O=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,s=new g(r);return e.ws||i(e,n),e.ws(o,(function(t,e){var n=e.query.channel,r=void 0===n?0:n,o=null;s.list[r]&&(o=s.list[r].on("data",(function(e){t.send(e)}))),t.on("close",(function(){o&&s.list[r]&&s.list[r].cancel(o)}))})),s},w=function(){return(w=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},_=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{c(r.next(t))}catch(t){i(t)}}function u(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,u)}c((r=r.apply(t,e||[])).next())}))},j=function(t,e){var n,r,o,i,s={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(i){return function(u){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return s.label++,{value:i[1],done:!1};case 5:s.label++,r=i[1],i=[0];continue;case 7:i=s.ops.pop(),s.trys.pop();continue;default:if(!(o=s.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){s=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){s.label=i[1];break}if(6===i[0]&&s.label<o[1]){s.label=o[1],o=i;break}if(o&&s.label<o[2]){s.label=o[2],s.ops.push(i);break}o[2]&&s.ops.pop(),s.trys.pop();continue}i=e.call(t,s)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,u])}}},x=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},S=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),s=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)s.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return s},P=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(S(arguments[e]));return t},E=function(){function t(t){var e=t.driver,n=x(t,["driver"]);this.queue=new a.SyncQueue,this.get=this._bind("get"),this.put=this._bind("put"),this.delete=this._bind("delete"),this.list=this._bind("list"),this.rename=this._bind("rename"),this.driver=e,this.options=n}return t.prototype._push=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return e.queue.push((function(){return t.call.apply(t,P([e],n))}))}},t.prototype._bind=function(t){var e=this;return this._push((function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return _(e,void 0,void 0,(function(){var e;return j(this,(function(r){switch(r.label){case 0:return[4,this.connect()];case 1:return e=r.sent(),[2,this._run(t,e,n)]}}))}))}))},t.prototype._run=function(t,e,n){return new Promise((function(r,o){e[t].apply(e,P(n,[function(n,i){n?(o(n),e.end()):(r(i||"operation successful."),"get"===t?i.once("close",(function(){return e.end()})):e.end())}]))}))},t.prototype.connect=function(){var t=this;return new Promise((function(e,n){var r=new t.driver;r.once("ready",(function(){e(r)})),r.once("error",(function(t){n(t),r.end()})),r.connect(w({},t.options))}))},t}(),q=n(5),k=function(t){return Object(q.createHash)("md5").update(t).digest("hex")},M=function(){return(M=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function F(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,s=M({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),u=new i.Client(e,i.credentials.createInsecure(),s);return new o({request:function(t,e,n){var r="/"+t+"/"+e;return new Promise((function(t,e){var o=function(t){return t};u.makeUnaryRequest(r,o,o,n,(function(n,r){n?e(n):t(r)}))}))}})}}])}));
1
+ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["pubo-node"]=e():t["pubo-node"]=e()}(this,(function(){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:r})},n.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},n.t=function(t,e){if(1&e&&(t=n(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)n.d(r,o,function(e){return t[e]}.bind(null,o));return r},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=6)}([function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("pubo-utils")},function(t,e){t.exports=require("pako")},function(t,e){t.exports=require("path")},function(t,e){t.exports=require("child_process")},function(t,e){t.exports=require("crypto")},function(t,e,n){"use strict";n.r(e),n.d(e,"JsonStorage",(function(){return u})),n.d(e,"initRtspVideos",(function(){return w})),n.d(e,"RtspVideosManager",(function(){return g})),n.d(e,"FtpClient",(function(){return E})),n.d(e,"md5",(function(){return F})),n.d(e,"createRpcClient",(function(){return M})),n.d(e,"PuboFileSystem",(function(){return R}));var r=n(0),o=n(2),i=function(){return(i=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},u=function(){function t(t){this._state={},this.path=t,this.init()}return t.prototype.init=function(){try{var t=Object(r.readFileSync)(this.path),e=o.inflate(t,{to:"string"});this._state=JSON.parse(e)}catch(t){this.state={}}},Object.defineProperty(t.prototype,"state",{get:function(){return this._state},set:function(t){var e=o.deflate(JSON.stringify(t)),n=Buffer.from(e);Object(r.writeFile)(this.path,n,(function(t){return t&&console.log(t)})),this._state=t},enumerable:!1,configurable:!0}),t.prototype.get=function(t){return t?this.state[t]:i({},this.state)},t.prototype.set=function(t,e){var n=i({},this.state);n[t]=e,this.state=n},t.prototype.merge=function(t){this.state=i(i({},this._state),t)},t}(),s=n(3),c=n(4),a=n(1),l=function(){return(l=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},f=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u},p=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(f(arguments[e]));return t},h=function(){function t(t,e){var n=this;this.eventEmitter=new a.Emitter,this.dog=new a.WatchDog({limit:10,onTimeout:function(){return n.connect()}}),this.url=t,this.options=l({},e),this.options.input||(this.options.input=["-rtsp_transport","tcp","-i"]),this.options.output||(this.options.output=["-f","mpegts","-codec:v","mpeg1video"]),this.connect(),this.dog.init()}return t.prototype.onMessage=function(t){this.dog.feed(),this.eventEmitter.emit("message",t.toString())},t.prototype.closeOld=function(){this.s&&(console.log("LOG Video-Server: "+this.url+" try to reconnect;"),this.s.kill(),this.s=null)},t.prototype.connect=function(){var t=this;this.closeOld();var e=p(this.options.input,[this.url],this.options.output,["-"]);this.s=Object(c.spawn)("ffmpeg",e,{detached:!1}),this.s.stderr.on("data",(function(e){return t.onMessage(e)})),this.s.stdout.on("data",(function(e){return t.eventEmitter.emit("data",e)}))},t.prototype.on=function(t,e){return this.eventEmitter.on(t,e)},t.prototype.cancel=function(t){this.eventEmitter.cancel(t)},t.prototype.destroy=function(){this.eventEmitter.clear(),this.dog.stop(),this.s&&(this.s.kill(),this.s=null)},t}(),y=function(){return(y=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},d=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},v=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u},m=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v(arguments[e]));return t},b=function(){function t(){this.path=Object(s.resolve)("resources/temp/videos.json")}return t.prototype.async=function(t){try{Object(r.writeFileSync)(this.path,JSON.stringify(t))}catch(t){console.log(t)}},Object.defineProperty(t.prototype,"data",{get:function(){try{var t=Object(r.readFileSync)(this.path);return console.log(t.toString()),JSON.parse(t.toString())}catch(t){return console.log(t),null}},enumerable:!1,configurable:!0}),t}(),g=function(){function t(t){this._system=[],this._customer=[],this.system=[],this.customer=[],this.storage=new b,this._system=t.map((function(t){return y(y({},t),{system:!0})})),this._customer=this.storage.data||[],this.system=t.map((function(t){var e=t.url,n=d(t,["url"]);return new h(e,n)})),this.customer=this._customer.map((function(t){var e=t.url,n=d(t,["url"]);return new h(e,n)}))}return Object.defineProperty(t.prototype,"list",{get:function(){return m(this.system,this.customer)},enumerable:!1,configurable:!0}),t.prototype.getVideos=function(){return m(this._system,this._customer)},t.prototype.create=function(t){if(this._customer.some((function(e){return e.url===t.url})))throw new Error("该地址已存在");var e=new h(t.url,t);this._customer.push(t),this.customer.push(e),this.storage.async(this._customer)},t.prototype.remove=function(t){if(t<this.system.length)throw new Error("系统配置不可删除");if(t>this.system.length+this.customer.length-1)throw new Error("超限");this._customer.splice(t-this.system.length-1,1),this.customer.splice(t-this.system.length-1,1)[0].destroy(),this.storage.async(this._customer)},t}(),w=function(t){var e=t.app,n=t.server,r=t.videos,o=t.path,i=t.expressWs,u=new g(r);return e.ws||i(e,n),e.ws(o,(function(t,e){var n=e.query.channel,r=void 0===n?0:n,o=null;u.list[r]&&(o=u.list[r].on("data",(function(e){t.send(e)}))),t.on("close",(function(){o&&u.list[r]&&u.list[r].cancel(o)}))})),u},O=function(){return(O=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)},_=function(t,e,n,r){return new(n||(n=Promise))((function(o,i){function u(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(u,s)}c((r=r.apply(t,e||[])).next())}))},j=function(t,e){var n,r,o,i,u={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;u;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return u.label++,{value:i[1],done:!1};case 5:u.label++,r=i[1],i=[0];continue;case 7:i=u.ops.pop(),u.trys.pop();continue;default:if(!(o=u.trys,(o=o.length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){u=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){u.label=i[1];break}if(6===i[0]&&u.label<o[1]){u.label=o[1],o=i;break}if(o&&u.label<o[2]){u.label=o[2],u.ops.push(i);break}o[2]&&u.ops.pop(),u.trys.pop();continue}i=e.call(t,u)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}},S=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},x=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u},P=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(x(arguments[e]));return t},E=function(){function t(t){var e=t.driver,n=S(t,["driver"]);this.queue=new a.SyncQueue,this.get=this._bind("get"),this.put=this._bind("put"),this.delete=this._bind("delete"),this.list=this._bind("list"),this.rename=this._bind("rename"),this.driver=e,this.options=n}return t.prototype._push=function(t){var e=this;return function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return e.queue.push((function(){return t.call.apply(t,P([e],n))}))}},t.prototype._bind=function(t){var e=this;return this._push((function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];return _(e,void 0,void 0,(function(){var e;return j(this,(function(r){switch(r.label){case 0:return[4,this.connect()];case 1:return e=r.sent(),[2,this._run(t,e,n)]}}))}))}))},t.prototype._run=function(t,e,n){return new Promise((function(r,o){e[t].apply(e,P(n,[function(n,i){n?(o(n),e.end()):(r(i||"operation successful."),"get"===t?i.once("close",(function(){return e.end()})):e.end())}]))}))},t.prototype.connect=function(){var t=this;return new Promise((function(e,n){var r=new t.driver;r.once("ready",(function(){e(r)})),r.once("error",(function(t){n(t),r.end()})),r.connect(O({},t.options))}))},t}(),q=n(5),F=function(t){return Object(q.createHash)("md5").update(t).digest("hex")},k=function(){return(k=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t}).apply(this,arguments)};function M(t){var e=t.url,n=t.options,r=void 0===n?{}:n,o=t.ServiceImp,i=t.Grpc,u=k({"grpc.max_send_message_length":-1,"grpc.max_receive_message_length":-1},r),s=new i.Client(e,i.credentials.createInsecure(),u);return new o({request:function(t,e,n){var r="/"+t+"/"+e;return new Promise((function(t,e){var o=function(t){return t};s.makeUnaryRequest(r,o,o,n,(function(n,r){n?e(n):t(r)}))}))}})}var J=function(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,o,i=n.call(t),u=[];try{for(;(void 0===e||e-- >0)&&!(r=i.next()).done;)u.push(r.value)}catch(t){o={error:t}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return u},I=function(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(J(arguments[e]));return t},N=function(t){return function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return new Promise((function(n,r){t.apply(void 0,I(e,[function(t){for(var e=[],o=1;o<arguments.length;o++)e[o-1]=arguments[o];t&&r(t),e.length<2?n(e):n(I(e))}]))}))}},R={read:N(r.read),readFile:N(r.readFile),writeFile:N(r.writeFile),readdir:N(r.readdir),open:N(r.open),close:N(r.close),write:N(r.write)}}])}));
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import type EventEmitter from 'events';
3
+ import * as fs from 'fs';
4
+ interface PuboFileSystemInterface {
5
+ read: <TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer?: TBuffer, offset?: number, length?: number, position?: fs.ReadPosition | null) => Promise<[number, TBuffer]>;
6
+ readFile: (path: fs.PathOrFileDescriptor, options?: ({
7
+ encoding?: null;
8
+ flag?: string;
9
+ } & EventEmitter.Abortable) | null) => Promise<Buffer>;
10
+ writeFile: (file: fs.PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) => Promise<void>;
11
+ readdir: (path: fs.PathLike, options?: BufferEncoding | {
12
+ encoding: BufferEncoding | null;
13
+ withFileTypes: false;
14
+ } | null) => Promise<string[]>;
15
+ open: (path: fs.PathLike, flags?: fs.OpenMode, mode?: fs.Mode | null) => Promise<number>;
16
+ close: (fd: number) => Promise<void>;
17
+ write: <TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null) => Promise<void>;
18
+ }
19
+ export declare const PuboFileSystem: PuboFileSystemInterface;
20
+ export {};
@@ -0,0 +1,76 @@
1
+ var __read = this && this.__read || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o),
5
+ r,
6
+ ar = [],
7
+ e;
8
+
9
+ try {
10
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
11
+ ar.push(r.value);
12
+ }
13
+ } catch (error) {
14
+ e = {
15
+ error: error
16
+ };
17
+ } finally {
18
+ try {
19
+ if (r && !r.done && (m = i["return"])) m.call(i);
20
+ } finally {
21
+ if (e) throw e.error;
22
+ }
23
+ }
24
+
25
+ return ar;
26
+ };
27
+
28
+ var __spread = this && this.__spread || function () {
29
+ for (var ar = [], i = 0; i < arguments.length; i++) {
30
+ ar = ar.concat(__read(arguments[i]));
31
+ }
32
+
33
+ return ar;
34
+ };
35
+
36
+ import * as fs from 'fs';
37
+
38
+ var callbackToPromise = function callbackToPromise(fn) {
39
+ return function () {
40
+ var args = [];
41
+
42
+ for (var _i = 0; _i < arguments.length; _i++) {
43
+ args[_i] = arguments[_i];
44
+ }
45
+
46
+ return new Promise(function (resolve, reject) {
47
+ fn.apply(void 0, __spread(args, [function (err) {
48
+ var rest = [];
49
+
50
+ for (var _i = 1; _i < arguments.length; _i++) {
51
+ rest[_i - 1] = arguments[_i];
52
+ }
53
+
54
+ if (err) {
55
+ reject(err);
56
+ }
57
+
58
+ if (rest.length < 2) {
59
+ resolve(rest);
60
+ } else {
61
+ resolve(__spread(rest));
62
+ }
63
+ }]));
64
+ });
65
+ };
66
+ };
67
+
68
+ export var PuboFileSystem = {
69
+ read: callbackToPromise(fs.read),
70
+ readFile: callbackToPromise(fs.readFile),
71
+ writeFile: callbackToPromise(fs.writeFile),
72
+ readdir: callbackToPromise(fs.readdir),
73
+ open: callbackToPromise(fs.open),
74
+ close: callbackToPromise(fs.close),
75
+ write: callbackToPromise(fs.write)
76
+ };
package/es/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { initRtspVideos, RtspVideosManager } from './rtsp-video';
3
3
  export { FtpClient } from './ftp-client';
4
4
  export { md5 } from './md5';
5
5
  export { createRpcClient } from './grpc';
6
+ export { PuboFileSystem } from './file-system';
package/es/index.js CHANGED
@@ -2,4 +2,5 @@ export { JsonStorage } from './storage/json';
2
2
  export { initRtspVideos, RtspVideosManager } from './rtsp-video';
3
3
  export { FtpClient } from './ftp-client';
4
4
  export { md5 } from './md5';
5
- export { createRpcClient } from './grpc';
5
+ export { createRpcClient } from './grpc';
6
+ export { PuboFileSystem } from './file-system';
@@ -0,0 +1,20 @@
1
+ /// <reference types="node" />
2
+ import type EventEmitter from 'events';
3
+ import * as fs from 'fs';
4
+ interface PuboFileSystemInterface {
5
+ read: <TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer?: TBuffer, offset?: number, length?: number, position?: fs.ReadPosition | null) => Promise<[number, TBuffer]>;
6
+ readFile: (path: fs.PathOrFileDescriptor, options?: ({
7
+ encoding?: null;
8
+ flag?: string;
9
+ } & EventEmitter.Abortable) | null) => Promise<Buffer>;
10
+ writeFile: (file: fs.PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions) => Promise<void>;
11
+ readdir: (path: fs.PathLike, options?: BufferEncoding | {
12
+ encoding: BufferEncoding | null;
13
+ withFileTypes: false;
14
+ } | null) => Promise<string[]>;
15
+ open: (path: fs.PathLike, flags?: fs.OpenMode, mode?: fs.Mode | null) => Promise<number>;
16
+ close: (fd: number) => Promise<void>;
17
+ write: <TBuffer extends NodeJS.ArrayBufferView>(fd: number, buffer: TBuffer, offset?: number | null, length?: number | null, position?: number | null) => Promise<void>;
18
+ }
19
+ export declare const PuboFileSystem: PuboFileSystemInterface;
20
+ export {};
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var __createBinding = this && this.__createBinding || (Object.create ? function (o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ Object.defineProperty(o, k2, {
6
+ enumerable: true,
7
+ get: function get() {
8
+ return m[k];
9
+ }
10
+ });
11
+ } : function (o, m, k, k2) {
12
+ if (k2 === undefined) k2 = k;
13
+ o[k2] = m[k];
14
+ });
15
+
16
+ var __setModuleDefault = this && this.__setModuleDefault || (Object.create ? function (o, v) {
17
+ Object.defineProperty(o, "default", {
18
+ enumerable: true,
19
+ value: v
20
+ });
21
+ } : function (o, v) {
22
+ o["default"] = v;
23
+ });
24
+
25
+ var __importStar = this && this.__importStar || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) {
29
+ if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
30
+ }
31
+
32
+ __setModuleDefault(result, mod);
33
+
34
+ return result;
35
+ };
36
+
37
+ var __read = this && this.__read || function (o, n) {
38
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
39
+ if (!m) return o;
40
+ var i = m.call(o),
41
+ r,
42
+ ar = [],
43
+ e;
44
+
45
+ try {
46
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
47
+ ar.push(r.value);
48
+ }
49
+ } catch (error) {
50
+ e = {
51
+ error: error
52
+ };
53
+ } finally {
54
+ try {
55
+ if (r && !r.done && (m = i["return"])) m.call(i);
56
+ } finally {
57
+ if (e) throw e.error;
58
+ }
59
+ }
60
+
61
+ return ar;
62
+ };
63
+
64
+ var __spread = this && this.__spread || function () {
65
+ for (var ar = [], i = 0; i < arguments.length; i++) {
66
+ ar = ar.concat(__read(arguments[i]));
67
+ }
68
+
69
+ return ar;
70
+ };
71
+
72
+ Object.defineProperty(exports, "__esModule", {
73
+ value: true
74
+ });
75
+ exports.PuboFileSystem = void 0;
76
+
77
+ var fs = __importStar(require("fs"));
78
+
79
+ var callbackToPromise = function callbackToPromise(fn) {
80
+ return function () {
81
+ var args = [];
82
+
83
+ for (var _i = 0; _i < arguments.length; _i++) {
84
+ args[_i] = arguments[_i];
85
+ }
86
+
87
+ return new Promise(function (resolve, reject) {
88
+ fn.apply(void 0, __spread(args, [function (err) {
89
+ var rest = [];
90
+
91
+ for (var _i = 1; _i < arguments.length; _i++) {
92
+ rest[_i - 1] = arguments[_i];
93
+ }
94
+
95
+ if (err) {
96
+ reject(err);
97
+ }
98
+
99
+ if (rest.length < 2) {
100
+ resolve(rest);
101
+ } else {
102
+ resolve(__spread(rest));
103
+ }
104
+ }]));
105
+ });
106
+ };
107
+ };
108
+
109
+ exports.PuboFileSystem = {
110
+ read: callbackToPromise(fs.read),
111
+ readFile: callbackToPromise(fs.readFile),
112
+ writeFile: callbackToPromise(fs.writeFile),
113
+ readdir: callbackToPromise(fs.readdir),
114
+ open: callbackToPromise(fs.open),
115
+ close: callbackToPromise(fs.close),
116
+ write: callbackToPromise(fs.write)
117
+ };
package/lib/index.d.ts CHANGED
@@ -3,3 +3,4 @@ export { initRtspVideos, RtspVideosManager } from './rtsp-video';
3
3
  export { FtpClient } from './ftp-client';
4
4
  export { md5 } from './md5';
5
5
  export { createRpcClient } from './grpc';
6
+ export { PuboFileSystem } from './file-system';
package/lib/index.js CHANGED
@@ -53,4 +53,13 @@ Object.defineProperty(exports, "createRpcClient", {
53
53
  get: function get() {
54
54
  return grpc_1.createRpcClient;
55
55
  }
56
+ });
57
+
58
+ var file_system_1 = require("./file-system");
59
+
60
+ Object.defineProperty(exports, "PuboFileSystem", {
61
+ enumerable: true,
62
+ get: function get() {
63
+ return file_system_1.PuboFileSystem;
64
+ }
56
65
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pubo-node",
3
- "version": "1.0.46",
3
+ "version": "1.0.48",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./es/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "@types/node": "^17.0.25",
23
23
  "grpc": "^1.24.11",
24
24
  "pako": "^2.0.4",
25
- "pubo-utils": "^1.0.43"
25
+ "pubo-utils": "^1.0.47"
26
26
  },
27
- "gitHead": "37b84fa2664f73b0b76a02eb48e276e80d2ac374"
27
+ "gitHead": "5fb47a8ce69047bbe86a1cf44ded2b07662a145c"
28
28
  }