cambricon.js 938 B

12345678910111213141516171819202122232425262728293031323334
  1. var cambricon = cambricon || {};
  2. cambricon.ModelFactory = class {
  3. match(context) {
  4. const stream = context.stream;
  5. const buffer = stream.peek(Math.min(20, stream.length));
  6. const text = Array.from(buffer).map((c) => String.fromCharCode(c)).join('');
  7. if (text.startsWith('\x7fMEF') || text.startsWith('cambricon_offline')) {
  8. return 'cambricon';
  9. }
  10. return '';
  11. }
  12. open(/* context, match */) {
  13. return Promise.resolve().then(() => {
  14. throw new cambricon.Error("File contains undocumented Cambricon data.");
  15. });
  16. }
  17. };
  18. cambricon.Error = class extends Error {
  19. constructor(message) {
  20. super(message);
  21. this.name = 'Error loading Cambricon model.';
  22. this.stack = undefined;
  23. }
  24. };
  25. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  26. module.exports.ModelFactory = cambricon.ModelFactory;
  27. }