{"action":"created","issue":{"url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/issues/3","repository_url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs","labels_url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/issues/3/labels{/name}","comments_url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/issues/3/comments","events_url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/issues/3/events","html_url":"https://github.com/fxfactorial/ocaml-nodejs/issues/3","id":150572173,"number":3,"title":"buffer#to_string gives buffer word count in string?","user":{"login":"wiredsister","id":3818802,"avatar_url":"https://avatars.githubusercontent.com/u/3818802?v=3","gravatar_id":"","url":"https://api.github.com/users/wiredsister","html_url":"https://github.com/wiredsister","followers_url":"https://api.github.com/users/wiredsister/followers","following_url":"https://api.github.com/users/wiredsister/following{/other_user}","gists_url":"https://api.github.com/users/wiredsister/gists{/gist_id}","starred_url":"https://api.github.com/users/wiredsister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wiredsister/subscriptions","organizations_url":"https://api.github.com/users/wiredsister/orgs","repos_url":"https://api.github.com/users/wiredsister/repos","events_url":"https://api.github.com/users/wiredsister/events{/privacy}","received_events_url":"https://api.github.com/users/wiredsister/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/labels/bug","name":"bug","color":"fc2929"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-04-23T16:33:18Z","updated_at":"2016-04-23T17:04:43Z","closed_at":null,"body":"With a json file like: \r\n\r\n```javascript\r\n\r\n{\r\n    \"name\" : \"Eridin, Destroyer of Worlds\",\r\n    \"description\" : \"It is unavoidable.\",\r\n    \"deck\" : \"Monsters\",\r\n    \"combat row\" : \"Not applicable\",\r\n    \"strength\" : \"Not applicable\",\r\n    \"special ability\" : \"Destroyer of Worlds\"\r\n}\r\n\r\n```\r\n\r\nI've got some code like: \r\n\r\n```ocaml\r\n\r\nlet my_json_example : Yojson.Safe.json =\r\n  try\r\n    match Nodejs.Fs.read_file_sync \"example.json\" with\r\n    | String s -> Yojson.Safe.from_string s\r\n    | Buffer b -> b#to_string () |> Yojson.Safe.from_string\r\n  with e -> raise e\r\n\r\n```\r\n\r\nWhen I print that, I'm getting the number 32. When I `wc` on that, I see that it's printing the word count of that buffer plus a new line character. When I do `int_of_string (buffer#length) |> Yojson.Safe.from_string` on that, I get the number 2 weirdly. \r\n\r\nExample: \r\n```bash\r\n\r\n$ wc example.json \r\n8  31 233 example.json\r\n\r\n```\r\n\r\nPretty sure the bindings have some bugs here: \r\n\r\n```ocaml\r\n\r\n  (* ...inside Buffer *)\r\n    method to_string ?(encoding=Utf_8) ?(start=0) ?end_ () : string =\r\n      (match end_ with\r\n       | None ->\r\n         [|to_js_str (string_of_encoding encoding); i start; i self#length|]\r\n       | Some (j : int) ->\r\n         [| to_js_str (string_of_encoding encoding); i start; i j|])\r\n      |> m raw_js \"toString\" |> Js.to_string\r\n\r\n```\r\n\r\nIf I can figure this out, I'll PR the fix. What's a good work around in the meantime and can you reproduce? \r\nThanks.\r\n"},"comment":{"url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/issues/comments/213787200","html_url":"https://github.com/fxfactorial/ocaml-nodejs/issues/3#issuecomment-213787200","issue_url":"https://api.github.com/repos/fxfactorial/ocaml-nodejs/issues/3","id":213787200,"user":{"login":"wiredsister","id":3818802,"avatar_url":"https://avatars.githubusercontent.com/u/3818802?v=3","gravatar_id":"","url":"https://api.github.com/users/wiredsister","html_url":"https://github.com/wiredsister","followers_url":"https://api.github.com/users/wiredsister/followers","following_url":"https://api.github.com/users/wiredsister/following{/other_user}","gists_url":"https://api.github.com/users/wiredsister/gists{/gist_id}","starred_url":"https://api.github.com/users/wiredsister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/wiredsister/subscriptions","organizations_url":"https://api.github.com/users/wiredsister/orgs","repos_url":"https://api.github.com/users/wiredsister/repos","events_url":"https://api.github.com/users/wiredsister/events{/privacy}","received_events_url":"https://api.github.com/users/wiredsister/received_events","type":"User","site_admin":false},"created_at":"2016-04-23T17:04:43Z","updated_at":"2016-04-23T17:04:43Z","body":"@fxfactorial, I think in your example above,\r\n`String.capitalize \"Hello World\"` would correctly give back `\"Hello World\"`. `String.uppercase \"Hello World\"` would give back `\"HELLO WORLD\"`."}}