Change write_file functions to no longer use :utf8 file mode option
This commit is contained in:
parent
a77fe7c56e
commit
092a9c60d1
2 changed files with 20 additions and 3 deletions
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -22,6 +22,24 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
|
|||
- Mix formatter configuration for using `defvocab` without parens
|
||||
|
||||
|
||||
### Changed
|
||||
|
||||
- `RDF.Serialization.Writer.write_file/4` which is the basis used by all the
|
||||
`write_file/3` and `write_file!/3` functions of all serialization format modules
|
||||
like `RDF.NTriples`, `RDF.Turtle`, `JSON.LD` etc. now opens file in a different
|
||||
mode: it no longer opens them with the [`:utf8` option](https://hexdocs.pm/elixir/File.html#open/2).
|
||||
First, this by default slowed down the writing, but more importantly could lead
|
||||
to unexpected encoding issues.
|
||||
This is a **breaking change**: If your code relied on this file mode, you can
|
||||
get the old behaviour, by specifying the `file_mode` on these functions
|
||||
accordingly as `[:utf8, :write, :exclusive]`. For example, to write a Turtle
|
||||
file with the old behaviour, you can do it like this:
|
||||
|
||||
```elixir
|
||||
RDF.Turtle.write_file!(some_data, some_path, file_mode: ~w[utf8 write exclusive]a)
|
||||
```
|
||||
|
||||
|
||||
[Compare v0.6.2...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.6.2...HEAD)
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ defmodule RDF.Serialization.Writer do
|
|||
- `:force` - If not set to `true`, an error is raised when the given file
|
||||
already exists (default: `false`)
|
||||
- `:file_mode` - A list with the Elixir `File.open` modes to be used for writing
|
||||
(default: `[:utf8, :write]`)
|
||||
(default: `[:write, :exclusive]`)
|
||||
|
||||
It returns `:ok` if successful or `{:error, reason}` if an error occurs.
|
||||
"""
|
||||
|
@ -59,7 +59,7 @@ defmodule RDF.Serialization.Writer do
|
|||
end
|
||||
|
||||
defp file_mode(_encoder, opts) do
|
||||
with file_mode = Keyword.get(opts, :file_mode, ~w[utf8 write exclusive]a) do
|
||||
with file_mode = Keyword.get(opts, :file_mode, ~w[write exclusive]a) do
|
||||
if Keyword.get(opts, :force) do
|
||||
List.delete(file_mode, :exclusive)
|
||||
else
|
||||
|
@ -67,5 +67,4 @@ defmodule RDF.Serialization.Writer do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue