Debian Codegraph @

tools/to-data-uri/to_data_uri.lpr

raw
1 {
2 Copyright 2013-2022 Michalis Kamburelis.
3
4 This file is part of "Castle Game Engine".
5
6 "Castle Game Engine" is free software; see the file COPYING.txt,
7 included in this distribution, for details about the copyright.
8
9 "Castle Game Engine" is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 ----------------------------------------------------------------------------
14 }
15
16 { Convert any file to data URI scheme.
17 See README.md for details. }
18
19 uses SysUtils, Classes, Base64, CastleParameters, CastleDownload,
20 CastleUriUtils, CastleInternalDataUri, CastleClassUtils;
21 var
22 MimeType: string;
23 Stream: TStream;
24 begin
25 EnableBlockingDownloads := true;
26 Parameters.CheckHigh(1);
27 Stream := Download(Parameters[1], [], MimeType);
28 try
29 { Note that MimeType may be empty if not recognized.
30 That's Ok, data: URI spec allows it. }
31 Writeln(StreamToDataUri(Stream, MimeType));
32 finally
33 FreeAndNil(Stream);
34 end;
35 end.