can pharo change encoding of a file?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

can pharo change encoding of a file?

Peter Uhnak
Hi,

is there a way to reencode a file from within Pharo?

e.g. I have a file in CP1250 encoding and I want to change it to UTF-8.

In linux I would do something like "recode cp1250..utf8 file.txt".

But can Pharo do that natively, or do I need to defer to the system with FFI/OSSubprocess?

Thanks,
Peter
Reply | Threaded
Open this post in threaded view
|

Re: can pharo change encoding of a file?

Guillermo Polito
You can, check the ZnCharacterReadStream and ZnCharacterWriteStream classes. You can configure them with an encoding and voilá.

Guille

On Tue, Jul 5, 2016 at 12:14 PM, Peter Uhnák <[hidden email]> wrote:
Hi,

is there a way to reencode a file from within Pharo?

e.g. I have a file in CP1250 encoding and I want to change it to UTF-8.

In linux I would do something like "recode cp1250..utf8 file.txt".

But can Pharo do that natively, or do I need to defer to the system with FFI/OSSubprocess?

Thanks,
Peter

Reply | Threaded
Open this post in threaded view
|

Re: can pharo change encoding of a file?

Sven Van Caekenberghe-2
Yes,

  ZnCharacterEncoder newForEncoding: #cp1250

gives you all you need.

You can use the stream classes Guile mentioned. Just make sure you do your underlying, basic file IO binary.

> On 05 Jul 2016, at 12:21, Guillermo Polito <[hidden email]> wrote:
>
> You can, check the ZnCharacterReadStream and ZnCharacterWriteStream classes. You can configure them with an encoding and voilá.
>
> Guille
>
> On Tue, Jul 5, 2016 at 12:14 PM, Peter Uhnák <[hidden email]> wrote:
> Hi,
>
> is there a way to reencode a file from within Pharo?
>
> e.g. I have a file in CP1250 encoding and I want to change it to UTF-8.
>
> In linux I would do something like "recode cp1250..utf8 file.txt".
>
> But can Pharo do that natively, or do I need to defer to the system with FFI/OSSubprocess?
>
> Thanks,
> Peter
>


Reply | Threaded
Open this post in threaded view
|

Re: can pharo change encoding of a file?

Peter Uhnak
Perfect! Thank you both.

Peter

On Tue, Jul 5, 2016 at 12:49 PM, Sven Van Caekenberghe <[hidden email]> wrote:
Yes,

  ZnCharacterEncoder newForEncoding: #cp1250

gives you all you need.

You can use the stream classes Guile mentioned. Just make sure you do your underlying, basic file IO binary.

> On 05 Jul 2016, at 12:21, Guillermo Polito <[hidden email]> wrote:
>
> You can, check the ZnCharacterReadStream and ZnCharacterWriteStream classes. You can configure them with an encoding and voilá.
>
> Guille
>
> On Tue, Jul 5, 2016 at 12:14 PM, Peter Uhnák <[hidden email]> wrote:
> Hi,
>
> is there a way to reencode a file from within Pharo?
>
> e.g. I have a file in CP1250 encoding and I want to change it to UTF-8.
>
> In linux I would do something like "recode cp1250..utf8 file.txt".
>
> But can Pharo do that natively, or do I need to defer to the system with FFI/OSSubprocess?
>
> Thanks,
> Peter
>