www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Failed to archive JPEG (ArchiveMember): Invalid UTF-8 sequence (at

reply Ki Rill <rill.ki yahoo.com> writes:
Please, help me solve the annoying error above. I've been 
refactoring and rewriting code for my archive utility called 
[zippo](https://github.com/rillki/zippo) and I face this error 
when it tries to archive a JPEG image.

I tracked it down to the following function that helps me add a 
new member to `ZipArchive`.

```D
void zipAddArchiveMember(ref ZipArchive zip, in string file) {
     import std.conv: to;
     import std.file: readText;
     import std.string: representation;

     ArchiveMember member = new ArchiveMember();
     member.name = file;
     writefln("%s", file);
     member.expandedData(file.readText().dup().representation());
     member.compressionMethod = CompressionMethod.deflate;
     zip.addMember(member);
}
```

Am I missing something?
Jan 13 2023
parent reply Adam D Ruppe <destructionator gmail.com> writes:
On Saturday, 14 January 2023 at 01:08:25 UTC, Ki Rill wrote:
 a JPEG image.

     member.expandedData(file.readText().dup().representation());
A jpeg image is not a text file. Read it with `std.file.read()` instead of `readText`. Then you can get rid of those useless dup.representation calls too.
Jan 13 2023
parent Ki Rill <rill.ki yahoo.com> writes:
On Saturday, 14 January 2023 at 01:13:33 UTC, Adam D Ruppe wrote:
 On Saturday, 14 January 2023 at 01:08:25 UTC, Ki Rill wrote:
 a JPEG image.

     
 member.expandedData(file.readText().dup().representation());
A jpeg image is not a text file. Read it with `std.file.read()` instead of `readText`. Then you can get rid of those useless dup.representation calls too.
Thank you for such a quick reply! It solved my issue!
Jan 13 2023