diff options
author | Benjamin Otte <otte@redhat.com> | 2023-04-12 22:33:09 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2023-04-12 23:00:47 +0200 |
commit | 32bd68cdee0cbebfb2abdfee1da49a0fd44eb271 (patch) | |
tree | 8f2ec30d9babb10cda9cb1bf4498e5209ac83fa8 /json-glib/json-glib-validate.c | |
parent | 6898e26be5d0edd611e3ffc7b7c16567337ccc4d (diff) | |
download | json-glib-wip/otte/validate-with-load-bytes.tar.gz |
validate: Use g_file_load_bytes()wip/otte/validate-with-load-bytes
That code can deal with files >4GB, the current inputstream loading code
cannot.
Diffstat (limited to 'json-glib/json-glib-validate.c')
-rw-r--r-- | json-glib/json-glib-validate.c | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/json-glib/json-glib-validate.c b/json-glib/json-glib-validate.c index b717275..0ceda7d 100644 --- a/json-glib/json-glib-validate.c +++ b/json-glib/json-glib-validate.c @@ -46,28 +46,29 @@ static gboolean validate (JsonParser *parser, GFile *file) { - GInputStream *in; + GBytes *bytes; GError *error; gboolean res = TRUE; - gboolean parse_res; - gboolean close_res; error = NULL; - in = (GInputStream *) g_file_read (file, NULL, &error); - if (in == NULL) + bytes = g_file_load_bytes (file, NULL, NULL, &error); + if (bytes == NULL) { /* Translators: the first %s is the program name, the second one * is the URI of the file, the third is the error message. */ - g_printerr (_("%s: %s: error opening file: %s\n"), + g_printerr (_("%s: %s: error reading file: %s\n"), g_get_prgname (), g_file_get_uri (file), error->message); g_error_free (error); return FALSE; } - parse_res = json_parser_load_from_stream (parser, in, NULL, &error); - if (!parse_res) + res = json_parser_load_from_data (parser, + g_bytes_get_data (bytes, NULL), + g_bytes_get_size (bytes), + &error); + if (!res) { /* Translators: the first %s is the program name, the second one * is the URI of the file, the third is the error message. @@ -75,20 +76,9 @@ validate (JsonParser *parser, g_printerr (_("%s: %s: error parsing file: %s\n"), g_get_prgname (), g_file_get_uri (file), error->message); g_clear_error (&error); - res = FALSE; } - close_res = g_input_stream_close (in, NULL, &error); - if (!close_res) - { - /* Translators: the first %s is the program name, the second one - * is the URI of the file, the third is the error message. - */ - g_printerr (_("%s: %s: error closing: %s\n"), - g_get_prgname (), g_file_get_uri (file), error->message); - g_clear_error (&error); - res = FALSE; - } + g_bytes_unref (bytes); return res; } |