<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>day53 &amp;mdash; Gerrit Niezen</title>
    <link>https://gerritniezen.com/tag:day53</link>
    <description>Maker of open-source software and hardware.</description>
    <pubDate>Mon, 20 Apr 2026 02:21:20 +0000</pubDate>
    <image>
      <url>https://i.snap.as/aMPXpIot.png</url>
      <title>day53 &amp;mdash; Gerrit Niezen</title>
      <link>https://gerritniezen.com/tag:day53</link>
    </image>
    <item>
      <title>Taking a deep dive into MTP: Part 4</title>
      <link>https://gerritniezen.com/taking-a-deep-dive-into-mtp-part-4?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[In the previous post on MTP we looked at how to retrieve the name of a file on an Android device using MTP. Let&#39;s see how to decode that filename:&#xA;&#xA;const array = new Uint8Array(data.payload);&#xA;const decoder = new TextDecoder(&#39;utf-16le&#39;);&#xA;filename = decoder.decode(array.subarray(1, array.byteLength - 2));&#xA;console.log(&#39;Filename:&#39;, filename);&#xA;&#xA;In short, we need to remove the length byte at the beginning and the zero terminator bytes at the end, and then decode it as UTF-16LE. To retrieve the file itself, we use the following (where CODE.GETOBJECT.value is 0x1009):&#xA;&#xA;const getFile = {&#xA;  type: 1,&#xA;  code: CODE.GETOBJECT.value,&#xA;  payload: [objectHandle],&#xA;};&#xA;await device.transferOut(0x01, buildContainerPacket(getFile));&#xA;&#xA;All that&#39;s left to do is to save the data that is returned to a file! (OK, I also need to write some code that handle files that are larger than the buffer we use for transferIn.)&#xA;&#xA;All the code is currently on a branch on GitHub:&#xA;https://github.com/tidepool-org/node-mtp/blob/pure-js/mtp.js&#xA;&#xA;Once I have it all working, I hope to replace the Node.js-specific bits so that it can run in the browser using WebUSB, and ideally have a proof-of-concept available on the web.&#xA;&#xA;---&#xA;I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.&#xA;&#xA;#100DaysToOffload #day53 #mtp&#xA;&#xA;iComment on this post/i&#xD;&#xA;div id=&#34;cusdis_thread&#34;/div]]&gt;</description>
      <content:encoded><![CDATA[<p>In the <a href="https://gerritniezen.com/taking-a-deep-dive-into-mtp-part-3">previous post on MTP</a> we looked at how to retrieve the name of a file on an Android device using MTP. Let&#39;s see how to decode that filename:</p>

<pre><code class="language-js">const array = new Uint8Array(data.payload);
const decoder = new TextDecoder(&#39;utf-16le&#39;);
filename = decoder.decode(array.subarray(1, array.byteLength - 2));
console.log(&#39;Filename:&#39;, filename);
</code></pre>

<p>In short, we need to remove the length byte at the beginning and the zero terminator bytes at the end, and then decode it as UTF-16LE. To retrieve the file itself, we use the following (where <code>CODE.GET_OBJECT.value</code> is <code>0x1009</code>):</p>

<pre><code class="language-js">const getFile = {
  type: 1,
  code: CODE.GET_OBJECT.value,
  payload: [objectHandle],
};
await device.transferOut(0x01, buildContainerPacket(getFile));
</code></pre>

<p>All that&#39;s left to do is to save the data that is returned to a file! (OK, I also need to write some code that handle files that are larger than the buffer we use for <code>transferIn</code>.)</p>

<p>All the code is currently on a branch on GitHub:
<a href="https://github.com/tidepool-org/node-mtp/blob/pure-js/mtp.js">https://github.com/tidepool-org/node-mtp/blob/pure-js/mtp.js</a></p>

<p>Once I have it all working, I hope to replace the Node.js-specific bits so that it can run in the browser using WebUSB, and ideally have a proof-of-concept available on the web.</p>

<hr/>

<p>I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting <a href="https://100daystooffload.com">https://100daystooffload.com</a>.</p>

<p><a href="https://gerritniezen.com/tag:100DaysToOffload" class="hashtag"><span>#</span><span class="p-category">100DaysToOffload</span></a> <a href="https://gerritniezen.com/tag:day53" class="hashtag"><span>#</span><span class="p-category">day53</span></a> <a href="https://gerritniezen.com/tag:mtp" class="hashtag"><span>#</span><span class="p-category">mtp</span></a></p>

<p><i>Comment on this post</i>
<div id="cusdis_thread" id="cusdis_thread"></div></p>
]]></content:encoded>
      <guid>https://gerritniezen.com/taking-a-deep-dive-into-mtp-part-4</guid>
      <pubDate>Fri, 03 Jul 2020 15:46:10 +0000</pubDate>
    </item>
  </channel>
</rss>