cambricon.js 958 B

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