* @private * This function checks if the file is in ASCII format or in Binary format * * It is done by searching keyword `solid` at the start of the file. * * An ASCII STL data must begin with `solid` as the first six bytes. * However, ASCII STLs lacking the SPACE after the `d` are
(data)
| 701 | * Search for `solid` to start anywhere after those prefixes. |
| 702 | */ |
| 703 | function isBinary(data) { |
| 704 | const reader = new DataView(data); |
| 705 | |
| 706 | // US-ASCII ordinal values for `s`, `o`, `l`, `i`, `d` |
| 707 | const solid = [115, 111, 108, 105, 100]; |
| 708 | for (let off = 0; off < 5; off++) { |
| 709 | // If "solid" text is matched to the current offset, declare it to be an ASCII STL. |
| 710 | if (matchDataViewAt(solid, reader, off)) return false; |
| 711 | } |
| 712 | |
| 713 | // Couldn't find "solid" text at the beginning; it is binary STL. |
| 714 | return true; |
| 715 | } |
| 716 | |
| 717 | /** |
| 718 | * @private |
no test coverage detected