@soga/utils 0.0.11 → 0.0.13

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/charcode.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveFileAsUtf8=exports.isUtf8File=exports.getBufferCharcodeName=exports.getFileCharcodeName=exports.getFileAllCharcode=void 0;const chardet_1=__importDefault(require("chardet")),fs_1=require("fs"),iconv_lite_1=__importDefault(require("iconv-lite")),buffer_1=require("./buffer"),file_1=require("./file"),getSampleBuffer=async e=>{const t=await(0,file_1.getFileSize)(e);let r=t-1;t>20480&&(r=20480);return await(0,buffer_1.getFileBufferSlice)(e,0,r)},parseCharcodeInfo=e=>{const t=e.find((e=>"UTF-8"===e.name)),r=e.find((e=>e.name.startsWith("GB")));return t?r?t.confidence>=r.confidence?t:r:t:r||e[0]},getFileAllCharcode=async e=>{const t=await getSampleBuffer(e);return chardet_1.default.analyse(t)};exports.getFileAllCharcode=getFileAllCharcode;const getFileCharcodeName=async e=>{const t=await(0,exports.getFileAllCharcode)(e);return parseCharcodeInfo(t).name};exports.getFileCharcodeName=getFileCharcodeName;const getBufferCharcodeName=e=>{const t=chardet_1.default.analyse(e);return parseCharcodeInfo(t).name};exports.getBufferCharcodeName=getBufferCharcodeName;const isUtf8File=async e=>"UTF-8"===await(0,exports.getFileCharcodeName)(e);exports.isUtf8File=isUtf8File;const saveFileAsUtf8=async(e,t)=>{await new Promise(((r,a)=>{const o=(0,fs_1.createReadStream)(e),i=(0,fs_1.createWriteStream)(t);o.on("error",(e=>{console.error(`读取文件时发生错误: ${e.message}`),a(e)})),i.on("error",(e=>{console.error(`写入文件时发生错误: ${e.message}`),a(e)})),(async()=>{try{const t=await(0,file_1.getFileSize)(e),s=Math.min(1023,t),c=await(0,buffer_1.getFileBufferSlice)(e,0,s),f=(0,exports.getBufferCharcodeName)(c);if("UTF-8"===f)o.pipe(i);else{const e=iconv_lite_1.default.decodeStream(f),t=iconv_lite_1.default.encodeStream("utf8");o.pipe(e).pipe(t).pipe(i).on("finish",(()=>{r(!0)})).on("error",(e=>{console.error(`转换文件时发生错误: ${e.message}`),a(e)}))}}catch(e){a(e)}})()}))};exports.saveFileAsUtf8=saveFileAsUtf8;
1
+ "use strict";var __importDefault=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.saveFileAsUtf8=exports.isUtf8File=exports.getBufferCharcodeName=exports.getFileCharcodeName=exports.getFileAllCharcode=void 0;const chardet_1=__importDefault(require("chardet")),fs_1=require("fs"),iconv_lite_1=__importDefault(require("iconv-lite")),buffer_1=require("./buffer"),file_1=require("./file"),getSampleBuffer=async e=>{const t=await(0,file_1.getFileSize)(e);let r=t-1;t>20480&&(r=20480);return await(0,buffer_1.getFileBufferSlice)(e,0,r)},parseCharcodeInfo=e=>{const t=e.find((e=>"UTF-8"===e.name)),r=e.find((e=>e.name.startsWith("GB")));return t?r?t.confidence>=r.confidence?t:r:t:r||e[0]},getFileAllCharcode=async e=>{const t=await getSampleBuffer(e);return chardet_1.default.analyse(t)};exports.getFileAllCharcode=getFileAllCharcode;const getFileCharcodeName=async e=>{const t=await(0,exports.getFileAllCharcode)(e);return parseCharcodeInfo(t).name};exports.getFileCharcodeName=getFileCharcodeName;const getBufferCharcodeName=e=>{const t=chardet_1.default.analyse(e);return parseCharcodeInfo(t).name};exports.getBufferCharcodeName=getBufferCharcodeName;const isUtf8File=async e=>"UTF-8"===await(0,exports.getFileCharcodeName)(e);exports.isUtf8File=isUtf8File;const saveFileAsUtf8=async(e,t)=>{await new Promise(((r,a)=>{(async()=>{try{const i=(0,fs_1.createReadStream)(e),o=(0,fs_1.createWriteStream)(t);i.on("error",(e=>{console.error(`读取文件时发生错误: ${e.message}`),a(e)})),o.on("error",(e=>{console.error(`写入文件时发生错误: ${e.message}`),a(e)})),o.on("finish",(()=>{r(!0)}));const s=await(0,file_1.getFileSize)(e),f=Math.min(1023,s),c=await(0,buffer_1.getFileBufferSlice)(e,0,f),l=(0,exports.getBufferCharcodeName)(c);if("UTF-8"===l)i.pipe(o);else{const e=iconv_lite_1.default.decodeStream(l),t=iconv_lite_1.default.encodeStream("utf8");i.pipe(e).pipe(t).pipe(o)}}catch(e){a(e)}})()}))};exports.saveFileAsUtf8=saveFileAsUtf8;
package/dist/main.d.ts CHANGED
@@ -6,3 +6,4 @@ export * from './charcode';
6
6
  export * from './language-map';
7
7
  export * from './language';
8
8
  export * from './error';
9
+ export * from './progress';
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./buffer"),exports),__exportStar(require("./gzip"),exports),__exportStar(require("./file"),exports),__exportStar(require("./hash"),exports),__exportStar(require("./charcode"),exports),__exportStar(require("./language-map"),exports),__exportStar(require("./language"),exports),__exportStar(require("./error"),exports);
1
+ "use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,r,t,o){void 0===o&&(o=t);var i=Object.getOwnPropertyDescriptor(r,t);i&&!("get"in i?!r.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return r[t]}}),Object.defineProperty(e,o,i)}:function(e,r,t,o){void 0===o&&(o=t),e[o]=r[t]}),__exportStar=this&&this.__exportStar||function(e,r){for(var t in e)"default"===t||Object.prototype.hasOwnProperty.call(r,t)||__createBinding(r,e,t)};Object.defineProperty(exports,"__esModule",{value:!0}),__exportStar(require("./buffer"),exports),__exportStar(require("./gzip"),exports),__exportStar(require("./file"),exports),__exportStar(require("./hash"),exports),__exportStar(require("./charcode"),exports),__exportStar(require("./language-map"),exports),__exportStar(require("./language"),exports),__exportStar(require("./error"),exports),__exportStar(require("./progress"),exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soga/utils",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },