<div dir="ltr"><blockquote style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" class="gmail_quote">ogr2ogr output.gpkg input.shp
Where would you read the Magic-Headers in this case?</blockquote><div>Before the input file is opened.</div><div>Read the first 100 bytes, compare with known signatures</div><div><br></div><div><br></div><div>if ((memcmp (blob, tiff_signature_big, 4) == 0) &&</div><div>    (memcmp (blob, tiff_signature_little, 4) == 0))</div><div>{</div><div>  return type_tiff;</div><div>}</div><div>else if (strncmp ((char *) blob, "%PDF-", 5) == 0)</div><div><div>{</div><div>  return type_pdf;</div><div>}</div></div><div><div>else if (strncmp ((char *) blob, "SQLite format 3", 14) == 0)</div><div><div>{</div><div>  return type_sqlite3; // even if the extension is called '.db' or '.blombo'</div><div>}</div></div></div><div><div>else if (strncmp ((char *) blob, "** This file contains an SQLite 2", 14) == 0)</div><div><div>{</div><div>  return type_sqlite2; // even if the extension is called '.db'</div><div>}</div></div></div><div><div>else if ((memcmp (blob, jp2_big, 12) == 0) &&</div><div>    (memcmp (blob, jp2_little, 12) == 0))</div><div>{</div><div>  return type_jp2;</div><div>}</div><div>else if ((memcmp (blob,jpeg1_signature, 2) == 0) &&</div><div>    (memcmp (blob, blob + size - 2, jpeg2_signature, 2) == 0))</div><div>{</div><div>  return type_jp2;</div><div>}</div></div><div>else // for other signatures</div><div><div>{</div><div>  return type_other;</div><div>}</div></div><div>else // for file extensions<br></div><div><div>{</div><div>  return type_kmz;</div><div>}</div></div><div><br></div><div>A Sqlite3 Database can have any type of extension.</div><div>Sometimes even '.sdb' is used, which normally is reserved for a Sybase-Database - which is also a file based Database with its own Magic Number.</div><div><br></div><div>To reliably determine this you use 'Magic Numbers', so that you know trough knowledge instead of guessing.</div><div><br></div><div>'Magic Numbers' were introduced to avoid this problem, since a user could rename the file to anything they want.<br></div><div><br></div><div>The above code is based on the used spatialite code, which read a BLOB, where the file is stored and thus has no file-name or extension to read.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><pre style="white-space:pre-wrap;color:rgb(0,0,0)">Reading the Magic-Header signatures first and then guessing from the file extension may be a better approach.</pre></blockquote><div>Even if t<span style="color:rgb(0,0,0);white-space:pre-wrap">he title uses the word '</span><font color="#000000"><span style="white-space:pre-wrap">Guessing', that is not a reason not so suggest a more practical</span> <span style="white-space:pre-wrap">approach that, is less error prone.</span></font></div><div><font color="#000000"><span style="white-space:pre-wrap"><br></span></font></div><div><font color="#000000"><span style="white-space:pre-wrap">Mark</span></font></div><div><br></div></div>