# vtkPNGReader/vtkPNGWriter : Update() consistency ?

**URL:** https://discourse.vtk.org/t/vtkpngreader-vtkpngwriter-update-consistency/7681
**Category:** Support
**Created:** [January 19, 2022, 10:31pm UTC](https://discourse.vtk.org/t/vtkpngreader-vtkpngwriter-update-consistency/7681 "2022-01-19T22:31:58Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicholas_yue/32/3751_2.png) [@Nicholas\_Yue](https://discourse.vtk.org/u/Nicholas_Yue)
#### Post date: [January 19, 2022, 10:31pm UTC](https://discourse.vtk.org/t/vtkpngreader-vtkpngwriter-update-consistency/7681/1 "2022-01-19T22:31:58Z")

</div>

Hi,

Calling Update() on vtkPNGReader performs a file read but calling Update() on vtkPNGWriter does not write out a proper PNG file, one has to call Write(), if I just call Update(), a file of the expected size is written but is not a valid PNG file.

I am building pipeline programmatically and was hoping I am able to call Update() for any vtkAlgorithm derived classes.

Have I done something wrong or misunderstood the purpose of Update() ?

```auto
import vtk

reader = vtk.vtkPNGReader()
reader.SetFileName('TestABC.png')

writer = vtk.vtkPNGWriter()
writer.SetFileName('nicholas.png')
writer.AddInputConnection(0,reader.GetOutputPort())
# writer.Write()
writer.Update()

```

Cheers

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [January 20, 2022, 9:16am UTC](https://discourse.vtk.org/t/vtkpngreader-vtkpngwriter-update-consistency/7681/2 "2022-01-20T09:16:43Z")

</div>

Using Write is the correct API for writer.  
It uses Update internally.

I agree that it is confusing though, I think vtkWriter should put that in protected members to avoid the confusion.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [January 20, 2022, 1:48pm UTC](https://discourse.vtk.org/t/vtkpngreader-vtkpngwriter-update-consistency/7681/3 "2022-01-20T13:48:09Z")

</div>

If you want to automate calls to `Update` or `Write`, you can just check if `vtkXMLWriterBase::SafeDownCast` returns `nullptr`, and call `Update` or `Write` accordingly.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [January 20, 2022, 1:51pm UTC](https://discourse.vtk.org/t/vtkpngreader-vtkpngwriter-update-consistency/7681/4 "2022-01-20T13:51:17Z")

</div>

Actually, no you can’t, we don’t have a base writer class for all writers… In addition to `vtkXMLWriterBase`, you’d need to check for `vtkImageWriter` and `vtkWriter` as well.
